home *** CD-ROM | disk | FTP | other *** search
/ Assassins - Ultimate CD Games Collection 4 / Assassins 4 (1999)(Weird Science).iso / workbench_games2 / mines_sweeper / mines.asm < prev    next >
Assembly Source File  |  1998-03-21  |  148KB  |  6,374 lines

  1.         
  2.  
  3.     ;************************************
  4.     ;*     MINESWEEPER                  *
  5.     ;************************************
  6.     ;by Andry of PEGAS
  7.     ;$VER: Source code for MineSweeper V0.76 by PEGAS (15.6.97)
  8.  
  9.     ;Feel free to use this source, but give me credits AT LEAST.
  10.  
  11. V='V'
  12. E='0'
  13. R='.'
  14. S='7'
  15. I='6'
  16.     MACHINE MC68020
  17.     ;To do:
  18.     ;    + MinWin_Left, MinWin_Top
  19.     ;    - scale sun and numbers
  20.  
  21.     ;    + all system calls: arguments to LONG, (+) base adr. to a6!!!
  22.     ;    + Use semaphores instead of Forbid()/Permit()
  23.     ;    + Be sure that comparsions on addresses are unsigned!!
  24.     ;    + Check functions for ALL possible returncodes. If possible r-codes
  25.     ;      are A, B or C, do not assume that C if not (A or B).
  26.     ;    - Try to understand and use memory pools.
  27.     ;    - first create AppIcon (AppMenu) before closing the window (if fails...)
  28.     ;    + LOAD/SAVE  -  if read/writebytes != expected then FAIL
  29.     ;    + check MEMF_PUBLIC
  30.     ;    + check return of ItemAddress
  31.  
  32.     ;    - adjust preferences
  33.     ;    - u preferenci (adjust) pridelat ke "screen size" GUESS
  34.  
  35.     ;    - version (.doc, $VER: , title (win/scr), about, source)
  36.     ;    - udelat z .doc .guide
  37.  
  38.         INCLUDE    "SOURCES:mines/mines.i"
  39.  
  40. TRAPRMB        MACRO
  41.         ori.l    #WFLG_RMBTRAP,([MyWindow],wd_Flags)
  42.         ENDM
  43. FREERMB        MACRO
  44.         andi.l    #~WFLG_RMBTRAP,([MyWindow],wd_Flags)
  45.         ENDM
  46. ;*********************************************************************************
  47.         SECTION    MineSweeper,CODE
  48.  
  49.         jmp    _IconStart
  50. _main
  51.         lea    (EB,PC),a0
  52.         move.l    4.w,(a0)
  53.  
  54.         bsr.w    CallOtherSweeper    ;also inits semaphore structure
  55.  
  56.     ;**clear the whole bss section
  57.         lea    BssStart,a0
  58.         lea    BssEnd,a1
  59. .clrbss        clr.l    (a0)+
  60.         cmpa.l    a0,a1
  61.         bne.s    .clrbss
  62.         move.l    #Allocated,AllocPos
  63.  
  64.     ;**Open some libraries first
  65.         bsr.w    OpenReqTools    ;open this at first!!
  66.         beq.w    noReqTools
  67.  
  68.     ;processor check (68020+)
  69.         movea.l    (EB,PC),a6
  70.         btst.b    #AFB_68020,(AttnFlags+1,a6)    ;MC_68020?
  71.         bne.s    .mcok            ;yes
  72.         lea    oldproc_Text,a1
  73.         lea    oldproc_Button,a2
  74.         bsr.w    InformationReq
  75.         bra.w    oldProcessor
  76.     ;kickstart 3.0+ check (V39+)
  77. .mcok        cmpi.w    #39,(LIB_VERSION,a6)
  78.         bhs.s    .ksok
  79.         lea    oldks_Text,a1
  80.         lea    oldks_Button,a2
  81.         bsr.w    InformationReq
  82.         bra.w    oldKickstart
  83.  
  84. .ksok
  85.         bsr.w    OpenPublicPort
  86.         tst.l    (MinesMsgPort,pc)
  87.         bne.s    .ppok
  88.         lea    nopubport_Text,a1
  89.         lea    nopubport_Button,a2
  90.         bsr.w    InformationReq
  91.         bra.w    noPublicPort
  92.  
  93. .ppok    ;**open "timer.device"
  94.         movea.l    (EB,PC),a6
  95.         jsr    (_LVOCreateMsgPort,a6)        ;MsgPort
  96.         move.l    d0,TimPort
  97.         beq.w    error_NoTimerDevice
  98.  
  99.         movea.l    d0,a0        ;replyport
  100.         move.l    #IOTV_SIZE,d0    ;size
  101.         jsr    (_LVOCreateIORequest,a6)        ;IORequest
  102.         move.l    d0,TimIoReq
  103.         bne.s    .ioreqok
  104. .deletemsgport    movea.l    TimPort,a0    ;delete MsgPort <=> IORequest=0
  105.         jsr    (_LVODeleteMsgPort,a6)
  106.         bra.w    error_NoTimerDevice
  107.  
  108. .ioreqok    movea.l    d0,a1    ;IORequest
  109.         move.l    #UNIT_VBLANK,d0
  110.         moveq    #0,d1
  111.         lea    TimDevName,a0
  112.         jsr    (_LVOOpenDevice,a6)        ;OpenDevice
  113.         tst.l    d0
  114.         beq.s    .timdevok
  115.         movea.l    TimIoReq,a0
  116.         jsr    (_LVODeleteIORequest,a6)
  117.         bra.s    .deletemsgport
  118.  
  119. .timdevok    movea.l    TimIoReq,a0
  120.         move.l    (IO_DEVICE,a0),TimDevBase
  121.  
  122. .devok        bsr.w    OpenIntuition    ;some libraries
  123.         beq.w    noIntuition
  124.         bsr.w    OpenGraphics
  125.         beq.w    noGraphics
  126.         bsr.w    OpenDos
  127.         beq.w    noDos
  128.         bsr.w    OpenGadtools
  129.         beq.w    noGadtools
  130.         bsr.w    OpenUtility
  131.         beq.w    noUtility
  132.  
  133.         bsr.w    GetOutput
  134.     ;**copy default palette to screen palette
  135.         lea    DefaultPalette,a0
  136.         lea    ScreenPalette,a1
  137.         moveq    #PALENTRIES*3+2-1,d0
  138. .loop        move.l    (a0)+,(a1)+
  139.         dbra    d0,.loop
  140.  
  141.     ;**Get preferences
  142.         bsr.w    GetStartDirs    ;get lock of start directory and go there
  143.         bsr.w    LoadPreferences
  144.         tst.l    MyPrefs        ;this MUST be valid
  145.         beq.w    exit_noprefs
  146.         bsr.w    LoadHiScores
  147.         bsr.w    OpenFont    ;open prefered font
  148.         bsr.w    FontToRT    ;set font to reqtools tags
  149. iconify_Return
  150.     ;**Open screen  (If set in prefs)
  151.         bsr.w    OpenMyScreen
  152.         bsr.w    LockScreen
  153.         tst.l    MyScreen
  154.         beq.w    error_NoScreen
  155.  
  156.         bsr.w    GetDRI    ;get DrawInfo
  157.         bsr.w    SetPalette    ;set colors
  158.         bsr.w    GetButtonSizes    ;get size of buttons
  159.     ;-set mimum of fields per row
  160.         move.l    #MINBARWIDTH,d0
  161.         divu.w    ButtWidth,d0
  162.         bfclr    d0{0:16}
  163.         beq.s    .noadd
  164.         addq.w    #1,d0
  165. .noadd        move.w    d0,MinRowBut
  166.  
  167.         bsr.w    GetVisualInfo
  168.         tst.l    VisualInfo
  169.         beq.w    error_NoVI
  170.     ;**create buttons gfx
  171.         bsr.w    CreateGfx
  172.         tst.l    MGGfx
  173.         beq.w    error_noGfx
  174.     ;**Set window parameters
  175.         bsr.w    GetScreenCenter
  176.         bsr.w    SetWinParams    ;due to MyPrefs
  177.         bsr.w    SetWinTagList
  178.         bsr.w    SetZoomParams
  179.         bsr.w    OpenMyWindow
  180.  
  181.         tst.l    MyWindow
  182.         beq.w    noWindow
  183.     ;**SetMenu
  184.         bsr.w    SetMenu    ;completely sets menu strip
  185.  
  186.         move.l    #IDCMPFLAGS,d0
  187.         tst.l    MenuStruct
  188.         beq.s    .0        ;No menu
  189.         or.l    #IDCMP_MENUPICK,d0
  190. .0        bsr.w    ChangeIDCMP
  191.         tst.l    ([MyWindow],wd_UserPort)    ;IDCMP allocated?
  192.         bne.s    .idcmpok
  193.         lea    noidcmp_Text,a1
  194.         lea    noidcmp_Button,a2
  195.         bsr.w    InformationReq
  196.         bra.w    noIDCMP
  197.  
  198. .idcmpok    tst.b    DisplayTooBig
  199.         beq.s    .skip2
  200.         lea    toobig_Text,a1
  201.         lea    toobig_Button,a2
  202.         bsr.w    InformationReq
  203.         clr.b    DisplayTooBig
  204. .skip2
  205.         bsr.w    AddGadget    ;add sun gadget
  206.  
  207.         move.l    GadtoolsBase,a6
  208.         movea.l    MyWindow,a0
  209.         suba.l    a1,a1
  210.         jsr    (_LVOGT_RefreshWindow,a6)    ;hmmm...they tell to do this..
  211.  
  212.         bsr.w    CheckShowXmas
  213.  
  214.     ;uniconifying?
  215.         tst.b    FromIconify
  216.         beq.s    .notic
  217.  
  218.         clr.b    FromIconify
  219.         bsr.w    PutAllToFront
  220.         tst.b    Play        ;were you playing?
  221.         beq.s    .nottofront    ;no
  222.         move.b    #RW_ACTUAL,d0
  223.         bsr.w    RedrawWindow
  224.         bsr.w    StartTimer
  225.         bra.s    .skipinit
  226. .notic
  227.         tst.b    ([MyPrefs],mprf_WActivate)
  228.         bne.s    .nottofront
  229.         movea.l    IntuiBase,a6
  230.         movea.l    MyScreen,a0
  231.         jsr    (_LVOScreenToFront,a6)
  232. .nottofront
  233.     ;**alloc and init PF
  234.         bsr.w    InitBeforeStart
  235.         tst.l    PFAdr
  236.         beq.w    ExitSweeper
  237. .skipinit
  238.         clr.b    FromIconify
  239. ;***Main loop*******************************************************
  240. ;**Don't forget the Disable,Pause flags!!!!!!!!!!
  241.  
  242. ;get signal bits of both ports
  243.         movea.l    MyWindow,a0
  244.         movea.l    (wd_UserPort,a0),a0
  245.         move.b    (MP_SIGBIT,a0),d0
  246.         move.b    d0,WinPortSigBit
  247.         moveq    #0,d1
  248.         bset    d0,d1
  249.         movea.l    (MinesMsgPort,pc),a0
  250.         move.b    (MP_SIGBIT,a0),d0
  251.         move.b    d0,PubPortSigBit
  252.         bset    d0,d1
  253.         move.l    d1,SignalBits
  254.  
  255. MainLoop
  256.     ;wait for signals from both ports
  257.         movea.l    (EB,PC),a6
  258.         move.l    SignalBits,d0
  259.         jsr    (_LVOWait,a6)
  260.  
  261.         move.b    WinPortSigBit,d1    ;wd_UserPort?
  262.         btst    d1,d0
  263.         bne.s    CollectLoop        ;yes
  264.  
  265.     ;else MineSweeper public port
  266. .collect    movea.l    (EB,PC),a6
  267.         movea.l    (MinesMsgPort,pc),a0
  268.         jsr    (_LVOGetMsg,a6)
  269.         tst.l    d0
  270.         beq.s    MainLoop    ;no more messages
  271.         movea.l    d0,a1
  272.         move.l    (am_ID,a1),d2
  273.         jsr    (_LVOReplyMsg,a6)
  274.         cmpi.l    #'MINE',d2
  275.         bne.s    .collect
  276.     ;ok a new MineSweeper was started. That means, bring my window to front
  277.     ;and activate.
  278.         bsr.w    PutAllToFront
  279.         bra.s    .collect
  280.  
  281. CollectLoop
  282.         movea.l    MyWindow,a2
  283.         movea.l    GadtoolsBase,a6
  284.         movea.l    (wd_UserPort,a2),a0
  285.         jsr    (_LVOGT_GetIMsg,a6)
  286.         tst.l    d0    ;just message for gadtools?
  287.         beq.s    MainLoop
  288.         movea.l    d0,a1
  289.     ;**copy message to my buffer
  290.         movea.l    d0,a0
  291.         lea    IntuiMessBuf,a2
  292.         moveq    #(im_SIZEOF/2)-1,d0
  293. .loop        move.w    (a0)+,(a2)+
  294.         dbra    d0,.loop
  295.  
  296.         jsr    (_LVOGT_ReplyIMsg,a6)    ;message in A1
  297.  
  298.         lea    IntuiMessBuf,a0
  299.         move.l    (im_Class,a0),d0    ;get message
  300.  
  301.     ;**Handle message in d0
  302.         cmpi.l    #IDCMP_CHANGEWINDOW,d0
  303.         beq.w    HandleNewSize
  304.         tst.b    IDidTheChange        ;still waiting for the window to resize?
  305.         bne.s    CollectLoop        ;yes
  306.         cmpi.l    #IDCMP_MOUSEMOVE,d0
  307.         beq.w    HandleMouseMove
  308.         cmpi.l    #IDCMP_ACTIVEWINDOW,d0
  309.         beq.w    HandleTimer
  310.         cmpi.l    #IDCMP_INTUITICKS,d0
  311.         beq.w    HandleTimer
  312.         cmpi.l    #IDCMP_MOUSEBUTTONS,d0
  313.         beq.w    HandleButtons
  314.         cmpi.l    #IDCMP_GADGETDOWN,d0
  315.         beq.w    HandleGadgetDown
  316.         cmpi.l    #IDCMP_GADGETUP,d0
  317.         beq.w    HandleGadgetUP
  318.         cmpi.l    #IDCMP_VANILLAKEY,d0
  319.         beq.w    HandleVanillaKeys
  320.         cmpi.l    #IDCMP_MENUPICK,d0
  321.         beq.w    MenuPick
  322.         cmpi.l    #IDCMP_CLOSEWINDOW,d0
  323.         beq.s    ExitSweeper
  324.  
  325.         bra.w    CollectLoop
  326. ;*******************************************************************
  327. ExitSweeper
  328. noIDCMP
  329.         bsr.w    ClearMenu
  330.         bsr.w    CloseMyWindow
  331. noWindow
  332. error_noPF
  333.         bsr.w    FreeGfx
  334. error_noGfx
  335.         bsr.w    FreeVisualInfo
  336. error_NoVI
  337.         bsr.w    CloseMyScreen
  338.  
  339.     ;check if highscores are saved
  340.         movea.l    MyPrefs,a0
  341.         tst.b    (mprf_Warn,a0)
  342.         bne.s    .dontsave
  343.         tst.b    (mhs_NewHiscore,a0)
  344.         beq.s    .dontsave
  345.         tst.b    (mhs_Valid,a0)
  346.         beq.s    .dontsave
  347.         bsr.w    mh_HiScores
  348. .dontsave
  349. error_NoScreen
  350.         bsr.w    CloseFont
  351. exit_noprefs
  352.         bsr.w    FreeStartDir
  353.  
  354.         movea.l    (EB,PC),a6
  355.         movea.l    UtilityBase,a1
  356.         jsr    (_LVOCloseLibrary,a6)
  357. noUtility    movea.l    (EB,PC),a6
  358.         movea.l    GadtoolsBase,a1
  359.         jsr    (_LVOCloseLibrary,a6)
  360. noGadtools
  361. noDos        movea.l    (EB,PC),a6
  362.         movea.l    _GfxBase,a1
  363.         jsr    (_LVOCloseLibrary,a6)
  364. noGraphics    movea.l    (EB,PC),a6
  365.         movea.l    IntuiBase,a1
  366.         jsr    (_LVOCloseLibrary,a6)
  367.  
  368. noIntuition    movea.l    (EB,PC),a6
  369.         movea.l    TimIoReq,a1
  370.         jsr    (_LVOCloseDevice,a6)
  371.         movea.l    TimIoReq,a0
  372.         jsr    (_LVODeleteIORequest,a6)
  373.         movea.l    TimPort,a0
  374.         jsr    (_LVODeleteMsgPort,a6)
  375.  
  376. noTimer        bsr.w    ClosePublicPort
  377. noPublicPort
  378. oldKickstart
  379. oldProcessor    movea.l    (EB,PC),a6
  380.         movea.l    _ReqToolsBase,a1
  381.         jsr    (_LVOCloseLibrary,a6)
  382.  
  383. noReqTools
  384.         move.l    DosBase,d2
  385.         beq.s    .nodos
  386.         move.l    (MyOut,pc),d1    ;get my output file
  387.         beq.s    .noout        ;exist?
  388.         movea.l    d2,a6
  389.         jsr    (_LVOClose,a6)    ;close it
  390.         tst.l    d0
  391.         bne.s    .noout        ;closed succesfully
  392.         lea    notclosed_Text,a0
  393.         bsr.w    PrintText
  394. .noout
  395.         movea.l    (EB,PC),a6
  396.         movea.l    d2,a1
  397.         jsr    (_LVOCloseLibrary,a6)
  398. .nodos
  399.         bsr.w    FreeAllMemory
  400.         bsr.w    FreeSemaphore
  401.  
  402.         moveq    #0,d0
  403.         rts
  404.  
  405. error_NoTimerDevice
  406.         lea    notimd_Text,a1
  407.         lea    notimd_Button,a2
  408.         bsr.w    InformationReq
  409.         bra.s    noTimer
  410.  
  411. ;*******************************************************************
  412. MenuPick    move.w    (im_Code,a0),d2
  413.     ;**Search for matching code
  414. MenuSearch    cmpi.w    #MENUNULL,d2
  415.         beq.w    mp_Exit
  416.         st    HandleNext    ;flag
  417.  
  418.         lea    MyMenu,a2
  419. .loop        cmpi.b    #NM_END,(mmi_Type,a2)
  420.         beq.s    mp_Exit
  421.         cmp.w    (mmi_Code,a2),d2
  422.         beq.s    .match
  423.         lea    (mmi_SIZEOF,a2),a2
  424.         bra.s    .loop
  425. .match        move.l    (mmi_Handler,a2),d0    ;check for handler
  426.         beq.s    mp_Skip        ;no handler
  427.         movea.l    d0,a0        ;is there any?
  428.         movem.l    d2/a2,-(sp)
  429.         jsr    (a0)        ;skip to a handler
  430.         movem.l    (sp)+,d2/a2
  431. mp_Skip        tst.b    HandleNext
  432.         beq.s    mp_Exit
  433.  
  434.         movea.l    IntuiBase,a6
  435.         movea.l    MenuStruct,a0
  436.         move.l    d2,d0
  437.         jsr    (_LVOItemAddress,a6)
  438.         movea.l    d0,a0
  439.  
  440.         move.w    (mi_NextSelect,a0),d2
  441.         bra.s    MenuSearch
  442. mp_Exit        bra.w    CollectLoop
  443.  
  444.  
  445. ;******************************************************************
  446. FLAG =2
  447. QMARK=3
  448. HandleButtons    clr.b    SunPressedOnce    ;interrupt double clicking
  449.         movea.l    a0,a2
  450.         tst.b    Disable
  451.         bne.w    CollectLoop
  452.         tst.b    Ready
  453.         beq.w    CollectLoop
  454.         tst.b    Pause
  455.         bne.w    CollectLoop
  456.  
  457.         move.w    (im_Code,a2),d3
  458.         btst    #7,d3        ;just an upstroke?
  459.         bne.w    CollectLoop    ;yes
  460.  
  461.         move.w    (im_MouseX,a2),d0
  462.         move.w    (im_MouseY,a2),d1
  463.         sub.w    MinPFX,d0    ;check range
  464.         bmi.w    CollectLoop
  465.         sub.w    MinPFY,d1
  466.         bmi.w    CollectLoop
  467.         cmp.w    PFXPix,d0
  468.         bhs.w    CollectLoop
  469.         cmp.w    PFYPix,d1
  470.         bhs.w    CollectLoop
  471.  
  472.         ext.l    d0
  473.         ext.l    d1
  474.         divu.w    ButtWidth,d0
  475.         divu.w    ButtHeight,d1
  476.         addq.w    #1,d0
  477.         addq.w    #1,d1
  478.         move.w    d0,LastX
  479.         move.w    d1,LastY
  480.         move.w    d1,d2
  481.         mulu.w    PFWidth,d2
  482.         add.w    d0,d2        ;button's offset
  483.         movea.l    PFAdr,a0
  484.         adda.w    PFSize,a0
  485.  
  486.         cmpi.w    #IECODE_LBUTTON,d3
  487.         beq.s    .lmb
  488.         cmpi.w    #IECODE_RBUTTON,d3
  489.         beq.s    .rmb
  490.         bra.w    CollectLoop
  491.  
  492. .rmb        movea.l    MyPrefs,a5
  493.         tst.b    (mprf_Question,a5)    ;QUESTION_MARK=YES?
  494.         beq.s    .2    ;yes
  495. .1        cmpi.b    #FLAG,(a0,d2.w)    ;flag?
  496.         beq.s    .removef    ;just remove
  497.         bra.s    .12skip
  498. .2        cmpi.b    #FLAG,(a0,d2.w)    ;flag?
  499.         beq.s    .question    ;set qmark
  500.         cmpi.b    #QMARK,(a0,d2.w)
  501.         beq.s    .removeq
  502.  
  503.     ;neither flag nor qmark
  504. .12skip        tst.b    (a0,d2.w)
  505.         beq.s    .notpressed
  506.         tst.b    (mprf_RMouseGame,a5)    ;NORMOUSEGAME?
  507.         bne.w    .ok        ;yes
  508.         movea.l    PFAdr,a1
  509.         tst.b    (a1,d2.w)    ;pressed-empty button?
  510.         beq.w    .ok        ;yes
  511.     ;check number of flags around this PRESSED button
  512.         movem.w    d0/d1,-(sp)
  513.         move.w    #FLAG,d1    ;item to check
  514.         move.w    d2,d4        ;offset
  515.         move.w    PFWidth,d2
  516.         bsr.w    GetAround
  517.         cmp.b    (a1,d4.w),d0    ;is num. of flags around equal to the number?
  518.         movem.w    (sp)+,d0/d1
  519.         bne.w    .ok        ;no
  520.  
  521.     ;now uncover all buttons around
  522.         bra.s    .skipsub
  523. .Uncover    ;d0-x  d1-y  d2-offset
  524.         move.w    d1,d2
  525.         mulu.w    PFWidth,d2
  526.         add.w    d0,d2
  527.         movem.w    d0-d2,-(sp)
  528.         bsr.w    ShowButton
  529.         cmpi.b    #mgg_Bomb/4,d0
  530.         movem.w    (sp)+,d0-d2
  531.         bne.s    .uncok
  532.         movea.l    PFAdr,a0
  533.         move.b    #mgg_Blowed/4,(a0,d2.w)
  534.         move.w    #mgg_Blowed/4,d2
  535.         movem.w    d0/d1,-(sp)
  536.         bsr.w    PutButton    ;show the blowed immediatly
  537.         movem.w    (sp)+,d0/d1
  538.         move.w    #-1,(4,sp)    ;set loose flag
  539. .uncok
  540.         rts
  541. .skipsub    clr.w    -(sp)        ;room for loose-flag
  542.         subq.w    #1,d0        ;1st line
  543.         subq.w    #1,d1
  544.         bsr.s    .Uncover
  545.         addq.w    #1,d0
  546.         bsr.s    .Uncover
  547.         addq.w    #1,d0
  548.         bsr.s    .Uncover
  549.  
  550.         subq.w    #2,d0        ;2nd line
  551.         addq.w    #1,d1
  552.         bsr.s    .Uncover
  553.         addq.w    #2,d0
  554.         bsr.s    .Uncover
  555.  
  556.         subq.w    #2,d0        ;3rd line
  557.         addq.w    #1,d1
  558.         bsr.s    .Uncover
  559.         addq.w    #1,d0
  560.         bsr.s    .Uncover
  561.         addq.w    #1,d0
  562.         bsr.s    .Uncover
  563.         tst.w    (sp)+        ;loose?
  564.         beq.w    .ok0
  565.         clr.b    Win
  566.         bra.w    .0
  567.  
  568. .notpressed    move.b    #FLAG,(a0,d2.w)    ;set a Flag
  569.         subq.w    #1,BCount
  570.         move.w    #mgg_Flag/4,d2
  571.         bsr.w    PutButton
  572.         bra.w    .ok
  573. .question    move.b    #QMARK,(a0,d2.w)    ;set qmark
  574.         addq.w    #1,BCount
  575.         move.w    #mgg_Question/4,d2
  576.         bsr.w    PutButton
  577.         bra.s    .ok
  578. .removef    addq.w    #1,BCount
  579. .removeq    clr.b    (a0,d2.w)
  580.         move.w    #mgg_Empty/4,d2
  581.         bsr.w    PutButton    ;put a single button
  582.         bra.s    .ok
  583.  
  584. .lmb        tst.b    Play
  585.         beq.w    .NotPlayingYet
  586. .cont        tst.b    FirstTime
  587.         beq.s    .cont1
  588.         clr.b    FirstTime
  589.         movea.l    PFAdr,a1
  590.         cmpi.b    #mgg_Bomb/4,(a1,d2.w)
  591.         bne.s    .cont1
  592.         bsr.w    RemoveBomb
  593.  
  594. .cont1        move.w    d2,-(sp)
  595.         bsr.w    ShowButton
  596.         move.w    (sp)+,d2
  597.  
  598.         cmpi.b    #mgg_Bomb/4,d0    ;found a bomb?
  599.         bne.s    .ok0
  600.         clr.b    Win        ;you loose
  601.         movea.l    PFAdr,a0
  602.         move.b    #mgg_Blowed/4,(a0,d2.w)
  603.         move.w    LastX,d0
  604.         move.w    LastY,d1
  605.         move.w    #mgg_Blowed/4,d2
  606.         bsr.w    PutButton
  607.         bra.s    .0
  608. .ok0        tst.w    WinCount
  609.         seq    Win
  610.         bne.s    .ok
  611. .0        bsr.w    EndPlaying
  612. .ok        lea    (.OldBC,pc),a0    ;redraw number of bombs (if changed)
  613.         move.w    BCount,d2
  614.         cmp.w    (a0),d2
  615.         beq.s    .exit
  616.         move.w    d2,(a0)
  617.         move.w    BCountX,d0
  618.         move.w    BCountY,d1
  619.         bsr.w    DrawNumber
  620. .exit        bra.w    CollectLoop
  621.  
  622. .OldBC        dc.w    0
  623.  
  624. .NotPlayingYet    st    Play    ;now playing
  625.         TRAPRMB
  626.         movem.w    d0-d2,-(sp)
  627.         move.l    a0,-(sp)
  628.         bsr.w    StartTimer
  629.         movea.l    (sp)+,a0
  630.         movem.w    (sp)+,d0-d2
  631. .not        bra.w    .cont
  632.  
  633. ;******************************************************************
  634. RemoveBomb
  635.         movem.l    a0/d0-d2/d4,-(sp)
  636.  
  637.         movea.l    PFAdr,a0
  638.         moveq    #-1,d7
  639.         move.w    d2,d4
  640.         move.w    PFWidth,d2
  641.         bsr.w    AddAround    ;IN: a0-PFAdr, d2-PFWidth, d4-offset, d7- value to add
  642.         clr.b    (a0,d4.w)
  643.         move.w    d4,-(sp)
  644.  
  645.         move.w    MaxRandRange,d0
  646.         bsr.w    Rand
  647.         movea.l    SeedFillStack,a0    ;contains offsets of free buttons
  648.         move.w    (a0,d0.w*2),d4
  649.         move.w    PFWidth,d2
  650.         movea.l    PFAdr,a0
  651.         moveq    #1,d7
  652.         bsr.w    AddAround
  653.         move.b    #mgg_Bomb/4,(a0,d4.w)
  654.  
  655.         move.w    (sp)+,d4
  656.         move.w    #mgg_Bomb/4,d1
  657.         bsr.w    GetAround    ;   ""    ,OUT: d0-number of bombs around
  658.         move.b    d0,(a0,d4.w)
  659.  
  660.         movem.l    (sp)+,a0/d0-d2/d4
  661.         rts
  662. ;******************************************************************
  663. HandleMouseMove    tst.b    Play
  664.         beq.s    .exit
  665.         tst.b    Disable
  666.         bne.s    .exit
  667.         tst.b    Pause
  668.         bne.s    .exit
  669.         move.w    (im_MouseX,a0),d0
  670.         move.w    (im_MouseY,a0),d1
  671.         sub.w    MinPFX,d0    ;check range
  672.         bmi.w    .out
  673.         sub.w    MinPFY,d1
  674.         bmi.w    .out
  675.         cmp.w    PFXPix,d0
  676.         bhs.s    .out
  677.         cmp.w    PFYPix,d1
  678.         bhs.s    .out
  679.     ;in
  680.         TRAPRMB
  681.         bra.w    CollectLoop
  682. .out        FREERMB
  683. .exit        bra.w    CollectLoop
  684. ;******************************************************************
  685. HandleGadgetDown    ;double-clicking on the sun gadget means iconify
  686.         lea    (.time,pc),a2
  687.         tst.b    SunPressedOnce    ;is this the first time?
  688.         bne.s    .testdouble    ;no
  689.         st    SunPressedOnce
  690.         move.l    (im_Seconds,a0),(a2)    ;save time of this event
  691.         move.l    (im_Micros,a0),4(a2)
  692.         bra.w    CollectLoop
  693.  
  694. .testdouble    clr.b    SunPressedOnce
  695.         move.l    (a2),d0        ;start seconds
  696.         move.l    4(a2),d1    ;      micros
  697.         move.l    (im_Seconds,a0),d2    ;current secs.
  698.         move.l    (im_Micros,a0),d3    ;current micros
  699.         movea.l    IntuiBase,a6
  700.         jsr    (_LVODoubleClick,a6)    ;double clicked?
  701.         tst.l    d0
  702.         beq.w    CollectLoop        ;no
  703.  
  704.         subq.l    #8,a7    ;to be compatible with MenuPick
  705.         bsr.w    mh_Iconify
  706.         addq.l    #8,a7
  707.         bra.w    CollectLoop
  708. .time        dc.l    0,0
  709. ;******************************************************************
  710. HandleGadgetUP    bsr.w    InitBeforeStart
  711.         tst.l    PFAdr
  712.         beq.w    ExitSweeper
  713.         bra.w    CollectLoop
  714. ;******************************************************************
  715. ESC    =    27
  716. HandleVanillaKeys
  717.         move.w    (im_Code,a0),d2
  718.         move.w    (im_Qualifier,a0),d3
  719.         pea    (.exit,pc)    ;!!!!!!!!!!!!!!!!!!!!!!!!!
  720.  
  721.         move.b    d2,d0
  722.         bsr.w    uppercaseD0
  723.         btst    #IEQUALIFIERB_LCOMMAND,d3
  724.         bne.s    .lramiga
  725.         btst    #IEQUALIFIERB_RCOMMAND,d3
  726.         bne.s    .lramiga
  727.  
  728.         cmpi.b    #'H',d0
  729.         beq.s    mh_HiScores
  730.         cmpi.b    #ESC,d2
  731.         beq.s    vk_Exit
  732.         cmpi.b    #'*',d0
  733.         beq.w    vk_Iconify
  734.  
  735.         cmpi.b    #'P',d0        ;set/break pause
  736.         beq.s    vk_Pause
  737.         cmpi.b    #' ',d2        ;SPACE=START
  738.         beq.s    .start
  739.         addq.l    #4,sp        ;(.exit,pc)
  740. .exit        bra.w    CollectLoop
  741.  
  742. .start        bsr.w    InitBeforeStart
  743.         tst.l    PFAdr
  744.         bne.s    .ok
  745.         addq.l    #4,sp
  746.         bra.w    ExitSweeper
  747. .ok        rts
  748.  
  749. .lramiga
  750.     ;test level change
  751.         cmpi.b    #'1',d0
  752.         blo.s    .no
  753.         cmpi.b    #'5',d0
  754.         bhi.s    .no
  755.         subi.b    #'0',d0
  756.         bsr.w    NewLevelNoMenu
  757.         rts
  758.  
  759. .no        cmpi.b    #'H',d0
  760.         beq.w    mh_HiScores
  761.         cmpi.b    #'Q',d0
  762.         beq.s    vk_Exit
  763.         cmpi.b    #'?',d0
  764.         beq.s    vk_About
  765.         cmpi.b    #'I',d0
  766.         beq.w    vk_Iconify
  767.         cmpi.b    #'A',d0
  768.         beq.w    vk_AdjustPrefs
  769.         cmpi.b    #'W',d0
  770.         beq.w    mh_SavePrefs
  771.  
  772.         cmpi.b    #'S',d0
  773.         beq.s    .start
  774.         cmpi.b    #'P',d0
  775.         beq.s    vk_Pause    ;set/break pause
  776.         rts
  777.  
  778. vk_Iconify    subq.l    #4,sp        ;to be compatible (see "Menu handlers")
  779.         bsr.w    mh_Iconify
  780.         addq.l    #4,sp
  781.         rts
  782. vk_AdjustPrefs    subq.l    #4,sp        ;to be compatible (see "Menu handlers")
  783.         bsr.w    mh_AdjustPrefs
  784.         addq.l    #4,sp
  785.         rts
  786.  
  787.  
  788. vk_Exit        addq.l    #4,sp
  789.         bra.w    ExitSweeper
  790. vk_About    bsr.w    mh_About
  791.         rts
  792. ;-----------------------------------------------------
  793. vk_Pause    movea.l    MyWindow,a0
  794.         movea.l    IntuiBase,a6
  795.         jsr    (_LVOZipWindow,a6)
  796.         rts
  797. ;------------------------------------
  798. pause_Make    FREERMB
  799.         bsr.w    StopTimer
  800.         st    Pause
  801.         move.b    ([MyPrefs],mprf_Level),PausedLevel
  802.     ;set titles
  803.         movea.l    IntuiBase,a6
  804.         movea.l    MyWindow,a0
  805.         move.w    (wd_LeftEdge,a0),([MyPrefs],mprf_ZoomLeft)    ;set prefs.
  806.         move.w    (wd_TopEdge,a0),([MyPrefs],mprf_ZoomTop)
  807.  
  808.         move.l    #-1,a1
  809.         lea    (.pausetitle,pc),a2
  810.         jsr    (_LVOSetWindowTitles,a6)
  811.  
  812.         rts
  813. .pausetitle    dc.b    'MineSweeper - Paused',0
  814.         cnop    0,4
  815.  
  816. pause_Cont    clr.b    Pause
  817.     ;set titles
  818.         movea.l    IntuiBase,a6
  819.         movea.l    MyWindow,a0
  820.         lea    MyWinTitle,a1
  821.         lea    MyWinScrTitle,a2
  822.         jsr    (_LVOSetWindowTitles,a6)
  823.  
  824.         move.b    ([MyPrefs],mprf_Level),d0
  825.         cmp.b    PausedLevel,d0
  826.         beq.s    .nochange
  827.         bra.w    NewLevel    ;rts
  828.  
  829. .nochange    tst.b    Disable
  830.         bne.s    .exit
  831.         tst.b    Play
  832.         bne.s    .playing
  833.         bsr.w    InitBeforeStart
  834.         tst.l    PFAdr
  835.         bne.s    .ok
  836.         addq.l    #4,sp
  837.         bra.w    ExitSweeper
  838. .ok        rts
  839.  
  840. .playing    TRAPRMB
  841.         move.b    #RW_ACTUAL,d0
  842.         bsr.w    RedrawWindow
  843.         bsr.w    StartTimer
  844. .exit        rts
  845. ;******************************************************************
  846. PutAllToFront    movea.l    IntuiBase,a6
  847.         movea.l    MyScreen,a0
  848.         jsr    (_LVOScreenToFront,a6)
  849.         movea.l    MyWindow,a2
  850.         movea.l    a2,a0
  851.         jsr    (_LVOWindowToFront,a6)
  852.         movea.l    a2,a0
  853.         jsr    (_LVOActivateWindow,a6)
  854.         rts
  855. ;******************************************************************
  856. StartTimer    tst.b    Pause
  857.         bne.s    .exit
  858.         movea.l    TimDevBase,a6
  859.         lea    OldSysTime,a0
  860.         jsr    (_LVOGetSysTime,a6)    ;set start point
  861.         st    TimerGo
  862. .exit        rts
  863.  
  864.  
  865. ClearTimer    clr.l    MyTime
  866.         clr.l    EndTime
  867.         clr.l    EndTime+4
  868.         movea.l    MyPrefs,a0
  869.         tst.b    (mprf_CountDown,a0)
  870.         beq.s    .zero
  871.  
  872.         move.b    (mprf_Level,a0),d0
  873.         subq.b    #1,d0
  874.         ext.w    d0
  875.         move.w    (mhs_BestTimes,a0,d0.w*4),d0
  876.         move.w    d0,MyTime+2
  877. .zero        clr.l    MyTime+4    ;no rts here!
  878. ;--------
  879. StopTimer    clr.b    TimerGo
  880.         rts
  881.  
  882. HandleTimer    tst.b    TimerGo
  883.         beq.s    .ht_exit
  884.     ;get current sys time
  885.         movea.l    TimDevBase,a6
  886.         lea    SysTime,a0
  887.         jsr    (_LVOGetSysTime,a6)    ;a0 is unchanged
  888.         movem.l    (a0),d4/d5    ;store
  889.         lea    OldSysTime,a1
  890.         jsr    (_LVOSubTime,a6)    ;new-old => new
  891.         movem.l    d4/d5,(a1)    ;write to OldSysTime
  892.         movea.l    a0,a1
  893.         movea.l    a0,a3        ;store
  894.         lea    MyTime,a0
  895.  
  896.         tst.b    ([MyPrefs],mprf_CountDown)
  897.         beq.s    .up
  898.         jsr    (_LVOSubTime,a6)
  899.         bra.s    .skip
  900. .up        jsr    (_LVOAddTime,a6)    ;add diference to my timer
  901. .skip
  902.         movea.l    a3,a1
  903.         lea    EndTime,a0
  904.         jsr    (_LVOAddTime,a6)
  905.  
  906.         bsr.w    RedrawTime
  907.  
  908.         cmpi.l    #MAXTIME,EndTime    ;do you play too long?
  909.         blt.s    .no
  910.  
  911.         clr.b    Win
  912.         bsr.w    EndPlaying
  913.         lea    toolong_Text,a1
  914.         lea    toolong_Button,a2
  915.         bsr.w    InformationReq
  916. .no
  917. .ht_exit    bra.w    CollectLoop
  918.  
  919. ;******************************************************************
  920. RedrawTime    move.w    TimeX,d0
  921.         move.w    TimeY,d1
  922.         move.w    MyTime+TV_SECS+2,d2
  923.         lea    (OldSec,pc),a0        ;time changed?
  924.         cmp.w    (a0),d2
  925.         beq.s    .exit
  926.         move.w    d2,(a0)
  927.         bsr.s    DrawNumber
  928. .exit        rts
  929.  
  930. OldSec        dc.w    0
  931. ;******************************************************************
  932. DrawNumber    ;IN: d2.w- number
  933.         ;    d0.w-x d1.w-y
  934.  
  935. MINUS    =    10
  936.         ext.l    d0
  937.         ext.l    d1
  938.         movem.l    d0/d1,-(sp)
  939.         bsr.s    Num2String04    ;IN:d2-num;OUT:a2-string
  940.  
  941.         movea.l    MyWindow,a3
  942.         movea.l    (wd_RPort,a3),a3
  943.     ;**draw bevelled box
  944.         movea.l    GadtoolsBase,a6
  945.         movem.l    (sp),d0/d1
  946.         movea.l    a3,a0
  947.         move.l    #NUMBBOXX,d2
  948.         move.l    #NUMBBOXY,d3
  949.         lea    dbb_TagList2,a1
  950.         jsr    (_LVODrawBevelBoxA,a6)
  951.     ;**draw number
  952.         movem.l    (sp)+,d0/d1
  953.         movea.l    IntuiBase,a6
  954.         movea.l    a2,a0
  955.         addq.l    #NUMX,d0
  956.         addq.l    #NUMY,d1
  957.         moveq    #4-1,d7    ;draw 4 digits
  958. .digitloop    move.b    (a0)+,d6
  959.         subi.b    #'0',d6        ;get offset
  960.         bpl.s    .ok
  961.         move.b    #MINUS,d6
  962. .ok        ext.w    d6
  963.         mulu.w    #NUMPLANESIZE*2,d6
  964.         addi.l    #rawNumbers,d6
  965.         lea    img_Number,a1
  966.         move.l    d6,(ig_ImageData,a1)    ;img
  967.         movem.l    d0/d1/a0,-(sp)
  968.         movea.l    a3,a0            ;rp
  969.         jsr    (_LVODrawImage,a6)
  970.         movem.l    (sp)+,d0/d1/a0
  971.         addi.w    #NUMNEXT,d0
  972.         dbra    d7,.digitloop
  973.         rts
  974.  
  975. ;******************************************************************
  976.     ;**convert number in d2 to a string
  977. Num2String04    ;IN:d2.w - number;OUT:a2 - ptr to string
  978.         lea    (numfstring04,pc),a2
  979.         bra.s    ns_Go    ;rts
  980. Num2String4    lea    (numfstring4,pc),a2
  981.  
  982. ns_Go        movem.l    d0/d1/a0/a1/a3/a6,-(sp)
  983.         lea    (dstream,pc),a1 ;data stream
  984.         move.w    d2,(a1)
  985.         movea.l    a2,a0    ;format string
  986.         lea    (numostring,pc),a3    ;output string
  987.         lea    (hChar,pc),a2
  988.         movea.l    (EB,PC),a6
  989.         jsr    (_LVORawDoFmt,a6)    ;returns ptr. to end of data stream
  990.                         ;(which I don't need..)
  991.         movem.l    (sp)+,d0/d1/a0/a1/a3/a6
  992.         lea    (numostring,pc),a2
  993.         rts
  994.  
  995. hChar        move.b    d0,(a3)+
  996.         rts
  997.  
  998. dstream        dc.w    0
  999. numfstring04    dc.b    '%04.d',0
  1000. numfstring4    dc.b    '%4.d',0
  1001. numostring    dcb.b    6,0
  1002.  
  1003.         cnop    0,4
  1004. Num2StringDec    ;IN:d0-number.l
  1005.         ;OUT:a0-ptr to string
  1006.         lea    (fstringdec,pc),a0
  1007.         bra.s    nsdh_Go
  1008. Num2StringHex    lea    (fstringhex,pc),a0
  1009.  
  1010. nsdh_Go        movem.l    d1-d7/a1-a6,-(sp)
  1011.         lea    (.dstream,pc),a1 ;data stream
  1012.         move.l    d0,(a1)
  1013.         lea    (.numostring,pc),a3    ;output string
  1014.         clr.l    (a3)            ;clear the string
  1015.         clr.l    4(a3)
  1016.         clr.l    8(a3)
  1017.         lea    (hChar,pc),a2
  1018.         movea.l    (EB,PC),a6
  1019.         jsr    (_LVORawDoFmt,a6)
  1020.         movem.l    (sp)+,d1-d7/a1-a6
  1021.         lea    (.numostring,pc),a0
  1022.         rts
  1023.  
  1024. .dstream    dc.l    0
  1025. .numostring    dcb.b    4*3,0
  1026. fstringdec    dc.b    '%lu',0    ;long, unsigned decimal
  1027. fstringhex    dc.b    '0x%08.lx',0
  1028.         cnop    0,4
  1029. ;******************************************************************
  1030. HandleNewSize    tst.b    DisplayTooBig
  1031.         beq.s    .skip
  1032.         lea    toobig_Text,a1
  1033.         lea    toobig_Button,a2
  1034.         bsr.w    InformationReq
  1035.         clr.b    DisplayTooBig
  1036. .skip
  1037.     ;**Changed size or just moved?
  1038.         movea.l    MyWindow,a0    ;check unexpected sizing
  1039.         move.w    WinWidth,d0
  1040.         cmp.w    (wd_Width,a0),d0
  1041.         bne.w    hns_unexp
  1042.         move.w    WinHeight,d0
  1043.         cmp.w    (wd_Height,a0),d0
  1044.         bne.w    hns_unexp
  1045.  
  1046.         tst.b    Pause    ;was the window shrinked?
  1047.         beq.s    setWinPos    ;no
  1048.         bsr.w    pause_Cont
  1049.         bra.w    CollectLoop
  1050.  
  1051. setWinPos    ;**set new position to MyPrefs
  1052.         movea.l    MyWindow,a1
  1053.     ;refresh values
  1054.         move.w    (wd_Width,a1),d0
  1055.         move.w    (wd_Height,a1),d1
  1056.         move.w    d0,WinWidth
  1057.         move.w    d1,WinHeight
  1058.         moveq    #0,d2
  1059.         move.b    (wd_BorderLeft,a1),d2
  1060.         sub.w    d2,d0
  1061.         move.b    (wd_BorderRight,a1),d2
  1062.         sub.w    d2,d0
  1063.         move.b    (wd_BorderTop,a1),d2
  1064.         sub.w    d2,d1
  1065.         move.b    (wd_BorderBottom,a1),d2
  1066.         sub.w    d2,d1
  1067.         move.w    d0,InnWidth
  1068.         move.w    d1,InnHeight
  1069.  
  1070.         move.w    (wd_LeftEdge,a1),d0
  1071.         move.w    (wd_TopEdge,a1),d1
  1072.         movea.l    MyPrefs,a0
  1073.         tst.b    (mprf_CenterWindow,a0)
  1074.         beq.s    .yes
  1075.         move.w    d0,(mprf_WinX,a0)
  1076.         move.w    d1,(mprf_WinY,a0)
  1077. .yes        move.w    d0,WinX
  1078.         move.w    d1,WinY
  1079.     ;**now redraw and accept new level
  1080.         tst.b    IDidTheChange    ;Me or user? (new level or moved?)
  1081.         bne.s    .newlevel
  1082.  
  1083.     ;moved => set new center
  1084.         move.w    WinWidth,d0
  1085.         asr.w    #1,d0
  1086.         add.w    WinX,d0
  1087.         move.w    d0,CenterPointX
  1088.         move.w    WinHeight,d0
  1089.         asr.w    #1,d0
  1090.         add.w    WinY,d0
  1091.         move.w    d0,CenterPointY
  1092.         bra.s    .skip
  1093.  
  1094. .newlevel    bsr.w    InitBeforeStart
  1095.         tst.l    PFAdr
  1096.         beq.w    ExitSweeper
  1097.  
  1098. .skip        clr.b    IDidTheChange
  1099.         bra.w    CollectLoop
  1100.  
  1101. hns_unexp    ;Size is not the same as requested by ChangeWindowBox
  1102.         tst.b    IDidTheChange    ;just low memory (or something...)?
  1103.         bne.s    .ok
  1104.     ;**check if the window was zoomed
  1105.         move.w    ZoomWidth,d0
  1106.         cmp.w    (wd_Width,a0),d0
  1107.         bne.s    .unexp
  1108.         move.w    ZoomHeight,d0
  1109.         cmp.w    (wd_Height,a0),d0
  1110.         bne.s    .unexp
  1111.     ;yes, the window was just zoomed
  1112.         bsr.w    pause_Make
  1113.         bra.w    CollectLoop
  1114.  
  1115. .unexp        lea    changed_Text,a1    ;or some stranger...?
  1116.         lea    changed_Button,a2
  1117.         bsr.w    InformationReq
  1118.         st    Disable
  1119.         bra.w    setWinPos
  1120.  
  1121. .ok        lea    unexp_Text,a1
  1122.         lea    unexp_Button,a2
  1123.         bsr.w    InformationReq
  1124.         move.b    LastLevel,d0
  1125.         bsr.w    NewLevelNoMenu
  1126.         clr.b    IDidTheChange
  1127.         bra.w    CollectLoop
  1128. ;************************************************************************
  1129. CheckShowXmas
  1130.     ;--get current year
  1131.         bsr.s    GetCurrDate
  1132.         lea    CurrDate,a0
  1133.         move.w    (year,a0),d0
  1134.  
  1135.         cmp.w    LastXmas,d0    ;new year?
  1136.         shi    TestXmas
  1137.         rts
  1138. ;************************************************************************
  1139. CheckXmas    ;check for xmas
  1140.         tst.b    TestXmas
  1141.         beq.s    .no
  1142.         bsr.s    GetCurrDate
  1143.         lea    CurrDate,a0
  1144.         cmpi.w    #24,(mday,a0)
  1145.         bne.s    .no
  1146.         cmpi.w    #12,(month,a0)
  1147.         bne.s    .no
  1148.  
  1149.         move.w    (year,a0),LastXmas
  1150.         lea    xmas_Text,a1
  1151.         lea    xmas_Button,a2
  1152.         bsr.w    InformationReq
  1153.         clr.b    TestXmas    ;don't show anymore
  1154.         st    ([MyPrefs],mhs_NewHiscore)
  1155. .no        rts
  1156. ;************************************************************************
  1157. GetCurrDate    movea.l    IntuiBase,a6
  1158.         lea    Ctime,a0    ;secs
  1159.         lea    (4,a0),a1    ;micros
  1160.         jsr    (_LVOCurrentTime,a6)
  1161.  
  1162.         movea.l    UtilityBase,a6
  1163.         move.l    (a0),d0        ;get curr. secs.
  1164.         lea    CurrDate,a0    ;structure to fill
  1165.         jsr    (_LVOAmiga2Date,a6)    ;get current date
  1166.         rts
  1167. ;************************************************************************
  1168. InitBeforeStart    tst.b    Pause
  1169.         bne.s    .exit
  1170.         FREERMB
  1171.         bsr.w    ClearTimer
  1172.         move.w    PFBombs,BCount
  1173.         move.l    #img_Sun,Gadget_Image
  1174.         move.b    #RW_START,d0
  1175.         bsr.w    RedrawWindow
  1176.  
  1177.         move.w    MyTime+2,StartTime    ;save real start time
  1178.         tst.b    ([MyPrefs],mprf_CountDown)
  1179.         beq.s    .ok
  1180.         addq.w    #1,MyTime+2
  1181. .ok
  1182.         st    Ready
  1183.         bsr.w    InitPF
  1184.         clr.b    Play
  1185.         clr.b    Win
  1186.         st    FirstTime
  1187.  
  1188.     ;set num. of buttons to press to win
  1189.         move.w    PFSize,d0
  1190.         sub.w    PFBombs,d0
  1191.         sub.w    PFWidth,d0
  1192.         sub.w    PFWidth,d0
  1193.         sub.w    PFHeight,d0
  1194.         sub.w    PFHeight,d0
  1195.         addq.w    #4,d0
  1196.         move.w    d0,WinCount
  1197.  
  1198.         bsr.w    CheckXmas
  1199. .exit        rts
  1200.  
  1201. ;-------------------------------------------
  1202. EndPlaying    bsr.w    StopTimer
  1203.         clr.b    Play
  1204.         clr.b    Ready
  1205.         FREERMB
  1206.  
  1207.     ;fix a silly bug with timer
  1208.         tst.b    ([MyPrefs],mprf_CountDown)
  1209.         beq.s    .nobug
  1210.         move.w    StartTime,d0
  1211.         cmp.w    MyTime+2,d0
  1212.         bge.s    .nobug
  1213.         move.w    d0,MyTime+2
  1214.  
  1215. .nobug        tst.b    Win
  1216.         beq.s    .00
  1217.         move.l    #img_SunWon,Gadget_Image
  1218.         bra.s    .11
  1219. .00        move.l    #img_SunLoose,Gadget_Image
  1220. .11
  1221.         move.b    #RW_END,d0
  1222.         bsr.w    RedrawWindow
  1223.  
  1224.         tst.b    Win
  1225.         beq.s    .0
  1226.  
  1227.         move.w    EndTime+2,d2
  1228.         bsr.s    CheckForScore    ;IN:d2.w-time
  1229. .0        rts
  1230. ;************************************************************************
  1231. CheckForScore    movea.l    MyPrefs,a0
  1232.         lea    (mhs_BestTimes,a0),a1
  1233.         lea    (mhs_BestNames,a0),a2
  1234.         move.b    (mprf_Level,a0),d0
  1235.         subq.b    #1,d0
  1236.         ext.w    d0
  1237.         pea    (.ret,pc)
  1238.         cmp.w    (a1,d0.w*4),d2
  1239.         blo.s    .setscore1
  1240.         cmp.w    (2,a1,d0.w*4),d2
  1241.         blo.s    .setscore2
  1242.         addq.l    #4,sp
  1243. .ret
  1244.         rts        ;you were not good enough!
  1245.  
  1246. .setscore1
  1247.         cmpi.b    #LCUSTOM-1,d0
  1248.         bne.s    .cont0
  1249.         move.w    (mhs_CustomWidth1,a0),(mhs_CustomWidth2,a0)
  1250.         move.w    (mhs_CustomHeight1,a0),(mhs_CustomHeight2,a0)
  1251.         move.w    (mhs_CustomBombs1,a0),(mhs_CustomBombs2,a0)
  1252.         move.w    PFWidth,d3
  1253.         subq.w    #2,d3
  1254.         move.w    d3,(mhs_CustomWidth1,a0)
  1255.         move.w    PFHeight,d3
  1256.         subq.w    #2,d3
  1257.         move.w    d3,(mhs_CustomHeight1,a0)
  1258.         move.w    PFBombs,(mhs_CustomBombs1,a0)
  1259. .cont0        move.w    (a1,d0.w*4),d1    ;shift scores
  1260.         move.w    d2,(a1,d0.w*4)
  1261.         move.w    d1,(2,a1,d0.w*4)
  1262.  
  1263.         mulu.w    #NAMELEN*2,d0    ;shift names
  1264.         lea    (a2,d0.w),a2    ;new1
  1265.         lea    (NAMELEN,a2),a0    ;old2
  1266.         movea.l    a2,a1
  1267. .cp0        move.b    (a1)+,(a0)+
  1268.         bne.s    .cp0
  1269.         bra.s    .setname
  1270.  
  1271. .setscore2    cmpi.b    #LCUSTOM-1,d0
  1272.         bne.s    .cont1
  1273.         move.w    PFWidth,d3
  1274.         subq.w    #2,d3
  1275.         move.w    d3,(mhs_CustomWidth2,a0)
  1276.         move.w    PFHeight,d3
  1277.         subq.w    #2,d3
  1278.         move.w    d3,(mhs_CustomHeight2,a0)
  1279.         move.w    PFBombs,(mhs_CustomBombs2,a0)
  1280. .cont1        move.w    d2,(2,a1,d0.w*4)
  1281.         mulu.w    #NAMELEN*2,d0
  1282.         lea    (NAMELEN,a2,d0.w),a2
  1283.  
  1284. .setname    movea.l    a2,a5    ;store
  1285.     ;**get players name
  1286.         movea.l    _ReqToolsBase,a6
  1287.         moveq    #NAMELEN-1,d0    ;max. name len
  1288.         lea    NameBuffer,a1
  1289.         lea    (entertext_Title,pc),a2
  1290.         suba.l    a3,a3
  1291.         lea    GSReqTags,a0    ;tags
  1292.         jsr    (_LVOrtGetStringA,a6)
  1293.         tst.l    d0
  1294.         bne.s    .gotit
  1295.         lea    (AnonymousPlayer,pc),a0
  1296.         bra.s    .cp1
  1297. .gotit        lea    NameBuffer,a0
  1298. .cp1        move.b    (a0)+,(a5)+
  1299.         bne.s    .cp1
  1300.         st    ([MyPrefs],mhs_NewHiscore)
  1301.         clr.b    ValidHSText
  1302.         bsr.w    mh_HiScores
  1303.         rts
  1304.  
  1305. AnonymousPlayer    dc.b    'anonym  :( ',0
  1306. entertext_Title    dc.b    'Hi-score',0
  1307.         cnop    0,4
  1308. ;************************************************************************
  1309. ;*******Menu handlers****************************************************
  1310. ;************************************************************************
  1311. ; warning: (sp) contains LONG,LONG,LONG -> 12 bytes  (see mh_quit)
  1312. ; a2 contains MyMenuItem addr. , d2-im_Code
  1313.  
  1314. mh_Level    movea.l    IntuiBase,a6
  1315.         movea.l    MenuStruct,a0
  1316.         move.l    d2,d0
  1317.         ext.l    d0    ;to be sure
  1318.         jsr    (_LVOItemAddress,a6)
  1319.         movea.l    d0,a0
  1320.  
  1321.         move.w    (mi_Flags,a0),d0    ;get flags
  1322.         andi.w    #CHECKED,d0        ;zero or CHECKED
  1323.         beq.s    mhl_exit
  1324.  
  1325.         lea    LevelItems,a1
  1326.         move.l    a2,d0
  1327.         sub.l    a1,d0
  1328.         divu.w    #mmi_SIZEOF,d0
  1329.         addq.b    #1,d0        ;d0 contains level number
  1330.  
  1331. NewLevel    ;IN:d0-mprf_Level
  1332.         movea.l    MyPrefs,a0
  1333.         move.b    (mprf_Level,a0),LastLevel
  1334.         move.b    d0,(mprf_Level,a0)
  1335.         tst.b    Pause
  1336.         bne.s    mhl_exit
  1337.         clr.b    Disable
  1338.         clr.b    HandleNext
  1339.         bsr.w    ResizeWindow
  1340. mhl_exit    rts
  1341.  
  1342. NewLevelNoMenu    ;IN:d0-mprf_Level
  1343.         ;changes checkmark in menu
  1344.         move.b    d0,d6    ;store
  1345.  
  1346.     ;clear old checkmark
  1347.         movea.l    MyPrefs,a2
  1348.         lea    LevelItems,a3
  1349.         move.b    (mprf_Level,a2),d0
  1350.         subq.b    #1,d0
  1351.         ext.w    d0
  1352.         mulu.w    #mmi_SIZEOF,d0
  1353.         move.w    (mmi_Code,a3,d0.w),d0
  1354.  
  1355.         movea.l    MenuStruct,a0
  1356.         ext.l    d0    ;to be sure
  1357.         movea.l    IntuiBase,a6
  1358.         jsr    (_LVOItemAddress,a6)
  1359.         movea.l    d0,a0
  1360.         andi.w    #~CHECKED,(mi_Flags,a0)    ;clear checkmark
  1361.     ;set new checkmark
  1362.         move.b    d6,d0
  1363.         subq.b    #1,d0
  1364.         ext.w    d0
  1365.         mulu.w    #mmi_SIZEOF,d0
  1366.         move.w    (mmi_Code,a3,d0.w),d0
  1367.  
  1368.         movea.l    MenuStruct,a0
  1369.         ext.l    d0    ;to be sure
  1370.         jsr    (_LVOItemAddress,a6)
  1371.         movea.l    d0,a0
  1372.         ori.w    #CHECKED,(mi_Flags,a0)    ;set checkmark
  1373.         move.b    d6,d0
  1374.         bra.s    NewLevel
  1375.  
  1376. ;************************************************************************
  1377. mh_About    lea    about_Text,a1
  1378.         lea    about_Button,a2
  1379.         lea    AboutTags,a0
  1380.         suba.l    a3,a3
  1381.         suba.l    a4,a4
  1382.         movea.l    _ReqToolsBase,a6
  1383.         jsr    (_LVOrtEZRequestA,a6)    ;I don't care about the results
  1384.         rts
  1385. ;************************************************************************
  1386. mh_Start    bsr.w    InitBeforeStart
  1387.         tst.l    PFAdr
  1388.         beq.s    mh_Quit
  1389.         rts
  1390. ;************************************************************************
  1391. mh_Pause    bra.w    vk_Pause    ;rts
  1392. ;************************************************************************
  1393. mh_Quit        lea    (12,sp),sp    ;rts,a2,d2
  1394.         bra.w    ExitSweeper
  1395. ;*****************************************************************
  1396. mh_HiScores    tst.b    ValidHSText
  1397.         bne.s    .show
  1398.         bsr.w    MakeHighScores
  1399.         st    ValidHSText
  1400. .show
  1401.         movea.l    MyPrefs,a0
  1402.         tst.b    (mhs_NewHiscore,a0)
  1403.         beq.s    .dontsave
  1404.         tst.b    (mhs_Valid,a0)
  1405.         beq.s    .dontsave
  1406.  
  1407.         lea    HiScoresButtonSave,a2
  1408.         bsr.s    .disphsc
  1409.         tst.l    d0
  1410.         beq.s    .skipsaving
  1411.         bsr.w    SaveHiScores
  1412. .skipsaving    rts
  1413.  
  1414. .dontsave    lea    HiScoresButton,a2
  1415. .disphsc    lea    HiScoresText,a1
  1416.         lea    HiScoresTags,a0
  1417.         suba.l    a3,a3
  1418.         suba.l    a4,a4
  1419.         movea.l    _ReqToolsBase,a6
  1420.         jsr    (_LVOrtEZRequestA,a6)
  1421.         rts
  1422.  
  1423. ;*****************************************************************
  1424. mh_SaveScores    bsr.w    SaveHiScores
  1425.         rts
  1426. ;*****************************************************************
  1427. mh_ClearCustom
  1428.         lea    surec_Text,a1
  1429.         lea    surec_Button,a2
  1430.         bsr.w    InformationReq
  1431.         tst.l    d0
  1432.         beq.s    .exit
  1433.         clr.b    ValidHSText
  1434.         movea.l    MyPrefs,a0
  1435.         st    (mhs_NewHiscore,a0)
  1436.         clr.b    (mhs_CustomName1,a0)
  1437.         clr.b    (mhs_CustomName2,a0)
  1438.         move.w    #MAXTIME,(mhs_CustomTime1,a0)
  1439.         move.w    #MAXTIME,(mhs_CustomTime2,a0)
  1440.         lea    (mhs_CustomInfo,a0),a0
  1441.         moveq    #(mhs_CIEnd-mhs_CustomInfo)/2-1,d0
  1442. .clr        clr.w    (a0)+
  1443.         dbra    d0,.clr
  1444.         bsr.s    mh_HiScores
  1445. .exit        rts
  1446. ;*****************************************************************
  1447. mh_ClearAll    lea    surea_Text,a1
  1448.         lea    surea_Button,a2
  1449.         bsr.w    InformationReq
  1450.         tst.l    d0
  1451.         beq.s    .exit
  1452.         clr.b    ValidHSText
  1453.         movea.l    MyPrefs,a0
  1454.         bsr.w    ClearHighScores
  1455.         bsr.w    mh_HiScores
  1456. .exit        rts
  1457. ;*****************************************************************
  1458. mh_AdjustPrefs    rts
  1459. ;*****************************************************************
  1460. newToolTypes    dc.l    0
  1461. nosavemem_Text    dc.b    'Not enough memory',0
  1462. nosavemem_Button dc.b    'I see..',0
  1463. notsaved_Text    dc.b    'Preferences couldn',39,'t be saved',0
  1464. notsaved_Button    dc.b    'I see..',0
  1465.         cnop    0,4
  1466. ;-----------------------------------------
  1467. SEGMENTSIZE    = TOOLTYPEITEMS*40
  1468. mh_SavePrefs
  1469.     ;alloc. mem for tool types array
  1470.         move.l    #SEGMENTSIZE,d7        ;d7-allocated size
  1471.  
  1472. mhsp_TryAgain    ;to this label jumps EndOfSpace
  1473.         move.l    d7,d6
  1474.         move.l    d7,d0            ;d6-couter
  1475.         move.l    #MEMF_PUBLIC,d1
  1476.         bsr.w    ADDALLOC
  1477.  
  1478.         lea    (newToolTypes,pc),a0
  1479.         move.l    d0,(a0)
  1480.         beq.w    sp_nomem
  1481.  
  1482.         movea.l    (newToolTypes,pc),a2
  1483.         lea    ((TOOLTYPEITEMS+1)*4,a2),a3    ;skip pointers
  1484.         subi.l    #(TOOLTYPEITEMS+1)*4,d6
  1485.         movea.l    MyPrefs,a5
  1486.         lea    PrefItems,a0
  1487.  
  1488. .sp_loop    tst.l    (a0)    ;end?
  1489.         beq.s    .done
  1490.         movea.l    (mpi_PItemName,a0),a4
  1491.         movea.l    (mpi_SaveHandler,a0),a1
  1492.         move.l    a3,(a2)+    ;save text pointer
  1493.  
  1494.     ;now create text of the tool type
  1495.         move.l    a0,-(sp)
  1496.         jsr    (a1)    ;IN:a3-tt_text a4-prefitem text, a5-MyPrefs
  1497.         movea.l    (sp)+,a0
  1498.  
  1499.         lea    (mpi_SIZEOF,a0),a0
  1500.         bra.s    .sp_loop
  1501. .done
  1502.         clr.l    (a2)        ;end of array of CHAR *
  1503.     ;*get tool types
  1504.         movea.l    (EB,PC),a6
  1505.         lea    (IconName,pc),a1
  1506.         moveq    #MinIconVer,d0
  1507.         jsr    (_LVOOpenLibrary,a6)    ;"icon.library" V36
  1508.         lea    (IconBase,pc),a0
  1509.         move.l    d0,(a0)
  1510.         beq.s    .noiconlib
  1511.  
  1512.         lea    ProgramName,a0
  1513.         movea.l    (IconBase,pc),a6
  1514.         jsr    (_LVOGetDiskObjectNew,a6)    ;get "mines.info" or something
  1515.         lea    (diskObj,pc),a0
  1516.         move.l    d0,(a0)
  1517.         beq.s    .closelib        ;shouldn't happen...
  1518.         movea.l    d0,a1
  1519.         movea.l    (newToolTypes,pc),(do_ToolTypes,a1)    ;set ToolTypes array
  1520.         lea    ProgramName,a0
  1521.         jsr    (_LVOPutDiskObject,a6)        ;and save it to icon
  1522.         tst.l    d0
  1523.         beq.s    .errorsaving
  1524.  
  1525. .freeobj    movea.l    (diskObj,pc),a0
  1526.         jsr    (_LVOFreeDiskObject,a6)
  1527. .closelib    move.l    (EB,PC),a6
  1528.         movea.l    (IconBase,pc),a1
  1529.         jsr    (_LVOCloseLibrary,a6)
  1530. .freemem    movea.l    (newToolTypes,pc),a1
  1531.         bsr.w    FreeMemBlock
  1532.  
  1533.         rts            ;exit this section
  1534. ;--------------------
  1535. .errorsaving    lea    (notsaved_Text,pc),a1
  1536.         lea    (notsaved_Button,pc),a2
  1537.         bsr.w    InformationReq
  1538.         bra.s    .freeobj
  1539.  
  1540. .noiconlib    lea    (noicon_Text,pc),a1    ;see LoadPreferences
  1541.         lea    (noicon_Button,pc),a2
  1542.         bsr.w    InformationReq
  1543.         bra.s    .freemem
  1544.  
  1545. sp_nomem    lea    (nosavemem_Text,pc),a1
  1546.         lea    (nosavemem_Button,pc),a2
  1547.         bsr.w    InformationReq
  1548.         rts
  1549. ;-------------------------------------------------------------
  1550. ;this piece of code allocates new block of memory, when the old is too small
  1551. EndOfSpace
  1552.         movea.l    (newToolTypes,pc),a1
  1553.         bsr.w    FreeMemBlock    ;free old buffer
  1554.     ;try to allocate more space
  1555.         addi.l    #SEGMENTSIZE,d7
  1556.         lea    (12,a7),a7    ;rts_tt_Write,rts_sp_Sub,movea.l (sp)+,a0
  1557.         bra.w    mhsp_TryAgain
  1558. ;-------------------------------------------------------------
  1559. tt_Write    ;Copies text from (a4) to (a3) without the zero byte.
  1560.         ;Checks if there is enough free memory for this operation.
  1561.  
  1562.         ;IN: a4-source text  a3-destination buffer (d6-counter)
  1563. .cp        subq.l    #1,d6
  1564.         bmi.w    EndOfSpace
  1565.         move.b    (a4)+,(a3)+
  1566.         bne.s    .cp
  1567.         subq.l    #1,a3    ;delete the zero byte
  1568.         addq.l    #1,d6
  1569.         rts
  1570.  
  1571. tt_WriteEqual    ;writes "=" to (a3)
  1572.         lea    (eqchar,pc),a4
  1573.         bra.s    tt_Write    ;don't use "bsr"
  1574.                     ;tt_Write would be 3rd iteration (must be 2nd)!
  1575. eqchar        dc.b    '=',0
  1576.         cnop    0,4
  1577. tt_WriteZero    ;writes zero byte and subcrements d6(counter).
  1578.         ;Checking for memory was already done by tt_Write.
  1579.         ;Only call this routine once after some tt_Write(s).
  1580.         clr.b    (a3)+
  1581.         subq.l    #1,d6
  1582.         rts
  1583. ;-------------------------------------------------------------
  1584. ;Save preferences handlers
  1585. ;IN: a3-tt_text  a4-prefitem text  a5-MyPrefs
  1586. ;OUT: d0 - 0=OK else ERROR
  1587. ;   changes also a3
  1588. ;in case of error is all memory free (I mean newToolTypes)
  1589.  
  1590. TOBRACKETS    MACRO    ;closes switch to brackets (e.G.  (WBLIKE)  )
  1591.             ;IN:a4-switch text
  1592.         movea.l    a4,a0        ;store
  1593.         lea    (lbrack,pc),a4    ;left bracket
  1594.         bsr.w    tt_Write
  1595.         movea.l    a0,a4        ;restore
  1596.         bsr.w    tt_Write
  1597.         lea    (rbrack,pc),a4    ;right bracket
  1598.         bsr.w    tt_Write
  1599.         ENDM
  1600. lbrack        dc.b    '(',0
  1601. rbrack        dc.b    ')',0
  1602.         cnop    0,4
  1603.  
  1604. WRITESWITCH    MACRO    ;IN:mprf_(Switch)
  1605.         tst.b    (\1,a5)    ;switch specified?
  1606.         bne.s    .yes
  1607.         TOBRACKETS
  1608.         bra.s    .exit
  1609. .yes        bsr.w    tt_Write
  1610. .exit        bra.w    tt_WriteZero    ;rts
  1611.         ENDM
  1612.  
  1613. WRITESTRUCTVAL    MACRO    ;IN: e.G.  MyScreen, sc_Width, w  (word)
  1614.         bsr.w    tt_Write
  1615.         bsr.w    tt_WriteEqual
  1616.         moveq    #0,d0
  1617.         move.\3    ([\1],\2),d0
  1618.         bsr.w    Num2StringDec
  1619.         movea.l    a0,a4
  1620.         bsr.w    tt_Write
  1621.         bra.w    tt_WriteZero
  1622.         ENDM
  1623.  
  1624. sp_PubScreen    bsr.w    tt_Write
  1625.         bsr.w    tt_WriteEqual
  1626.         move.l    (mprf_PubNameAdr,a5),d0    ;any PubScreen name?
  1627.         bne.s    .nameok            ;yes
  1628.         lea    (nopubname,pc),a4
  1629.         bra.s    .skp
  1630. .nameok        movea.l    d0,a4
  1631. .skp        bsr.w    tt_Write
  1632.         bra.w    tt_WriteZero    ;rts
  1633. nopubname    dc.b    '<Name>',0
  1634.         cnop    0,4
  1635. ;--------------------------------------
  1636. sp_CustomScreen    WRITESWITCH    mprf_CustomScreen
  1637. ;--------------------------------------
  1638. sp_NotCenter    WRITESWITCH    mprf_CenterWindow
  1639. ;--------------------------------------
  1640. sp_NotActiv    WRITESWITCH    mprf_WActivate
  1641. ;--------------------------------------
  1642. sp_NoQuest    WRITESWITCH    mprf_Question
  1643. ;--------------------------------------
  1644. sp_DeadQ    WRITESWITCH    mprf_DeadQ
  1645. ;--------------------------------------
  1646. sp_CountD    WRITESWITCH    mprf_CountDown
  1647. ;--------------------------------------
  1648. sp_NoRMouse    WRITESWITCH    mprf_RMouseGame
  1649. ;--------------------------------------
  1650. sp_WBLike    WRITESWITCH    mprf_WBLike
  1651. ;--------------------------------------
  1652. sp_Warn        WRITESWITCH    mprf_Warn
  1653. ;--------------------------------------
  1654. sp_Scale    WRITESWITCH    mprf_ScaleGfx
  1655. ;--------------------------------------
  1656. sp_ModeID    bsr.w    tt_Write
  1657.         bsr.w    tt_WriteEqual
  1658.         move.l    (mprf_ModeID,a5),d0
  1659.         bsr.w    Num2StringHex    ;IN:d0-number.l, OUT:a0-string
  1660.         movea.l    a0,a4
  1661.         bsr.w    tt_Write
  1662.         bra.w    tt_WriteZero
  1663. ;--------------------------------------
  1664. sp_SizeX    WRITESTRUCTVAL    MyScreen,sc_Width,w
  1665. ;--------------------------------------
  1666. sp_SizeY    WRITESTRUCTVAL    MyScreen,sc_Height,w
  1667. ;--------------------------------------
  1668. sp_WinX        WRITESTRUCTVAL    MyPrefs,mprf_WinX,w
  1669. ;--------------------------------------
  1670. sp_WinY        WRITESTRUCTVAL    MyPrefs,mprf_WinY,w
  1671. ;--------------------------------------
  1672. sp_ZoomX    WRITESTRUCTVAL    MyPrefs,mprf_ZoomLeft,w
  1673. ;--------------------------------------
  1674. sp_ZoomY    WRITESTRUCTVAL    MyPrefs,mprf_ZoomTop,w
  1675. ;--------------------------------------
  1676. sp_Level    bsr.w    tt_Write
  1677.         bsr.w    tt_WriteEqual
  1678.         move.b    (mprf_Level,a5),d0
  1679.         subq.b    #1,d0
  1680.         ext.w    d0
  1681.         movea.l    (.levTable,pc,d0.w*4),a4    ;get level name
  1682.         bsr.w    tt_Write
  1683.         bra.w    tt_WriteZero
  1684.  
  1685. .levTable    dc.l    ttEASY,ttMEDIUM,ttHARD,ttPROFI,ttCUSTOM
  1686. ;--------------------------------------
  1687. sp_Iconify    bsr.w    tt_Write
  1688.         bsr.w    tt_WriteEqual
  1689.         move.b    (mprf_Iconify,a5),d0
  1690.         ext.w    d0
  1691.         movea.l    (.icTable,pc,d0.w*4),a4
  1692.         bsr.w    tt_Write
  1693.         bra.w    tt_WriteZero
  1694.  
  1695. .icTable    dc.l    iconIcon,iconMenu
  1696. ;--------------------------------------
  1697. sp_CusWid    WRITESTRUCTVAL    MyPrefs,mprf_CustomWidth,w
  1698. ;--------------------------------------
  1699. sp_CusHei    WRITESTRUCTVAL    MyPrefs,mprf_CustomHeight,w
  1700. ;--------------------------------------
  1701. sp_CusBom    WRITESTRUCTVAL    MyPrefs,mprf_CustomBombs,w
  1702. ;--------------------------------------
  1703. sp_Font        bsr.w    tt_Write
  1704.         bsr.w    tt_WriteEqual
  1705.         move.l    (mprf_FontName,a5),d0
  1706.         beq.s    .default
  1707.         movea.l    d0,a4
  1708.         bra.s    .skp
  1709. .default    lea    (defaultText,pc),a4
  1710. .skp        bsr.w    tt_Write
  1711.         bra.w    tt_WriteZero
  1712. ;--------------------------------------
  1713. sp_FontSize    bsr.w    tt_Write
  1714.         bsr.w    tt_WriteEqual
  1715.         move.w    (mprf_FontSize,a5),d0
  1716.         bne.s    .ok
  1717.     ;zero font size means DESIGNED font
  1718.         lea    (designedText,pc),a4
  1719.         bra.s    .skip
  1720. .ok        ext.l    d0
  1721.         bsr.w    Num2StringDec
  1722.         movea.l    a0,a4
  1723. .skip        bsr.w    tt_Write
  1724.         bra.w    tt_WriteZero
  1725.  
  1726. ;--------------------------------------
  1727. sp_Palette    bsr.w    tt_Write
  1728.         bsr.w    tt_WriteEqual
  1729.         move.b    (mprf_PaletteType,a5),d0
  1730.         beq.s    .colortable
  1731.         subq.b    #1,d0
  1732.         ext.w    d0
  1733.         movea.l    (.paltypes,pc,d0.w*4),a4
  1734.         bsr.w    tt_Write
  1735. .exit        bra.w    tt_WriteZero
  1736.  
  1737. .colortable    lea    ScreenPalette+4,a1
  1738.         move.b    #PALENTRIES,d2
  1739.  
  1740. .ctloop        moveq    #0,d0
  1741.         move.b    (3,a1),d1    ;RED
  1742.         bfins    d1,d0{8:8}
  1743.         move.b    (7,a1),d1    ;GREEN
  1744.         bfins    d1,d0{16:8}
  1745.         move.b    (11,a1),d1    ;BLUE
  1746.         bfins    d1,d0{24:8}
  1747.         bsr.w    Num2StringHex
  1748.         movea.l    a0,a4
  1749.         bsr.w    tt_Write
  1750.         lea    (3*4,a1),a1
  1751.         subq.b    #1,d2
  1752.         beq.s    .exit
  1753.         lea    (.comma,pc),a4
  1754.         bsr.w    tt_Write
  1755.         bra.s    .ctloop
  1756.  
  1757. .paltypes    dc.l    ptStandard,ptMagicWB,ptWBLike
  1758. .comma        dc.b    ',',0
  1759.         cnop    0,4
  1760.  
  1761. ;--------------------------------------
  1762. sp_GfxType    bsr.w    tt_Write
  1763.         bsr.w    tt_WriteEqual
  1764.         move.b    (mprf_GfxType,a5),d0
  1765.         ext.w    d0
  1766.         movea.l    (.gtype,pc,d0.w*4),a4
  1767.         bsr.w    tt_Write
  1768.         bra.w    tt_WriteZero
  1769.  
  1770. .gtype        dc.l    gfxStandard,gfxMagicWB
  1771. ;*****************************************************************
  1772. mh_JoinScores
  1773.         clr.w    LastXmas
  1774.     ;alloc JoinPrefsBuf
  1775.         move.l    #prf_SIZEOF,d0
  1776.         moveq    #0,d1
  1777.         bsr.w    ADDALLOC
  1778.         move.l    d0,JoinPrefsBuf
  1779.         beq.w    fatalerror
  1780.  
  1781.     ;alloc file requester
  1782.         movea.l    _ReqToolsBase,a6
  1783.         move.l    #RT_FILEREQ,d0
  1784.         suba.l    a0,a0    ;no tags
  1785.         jsr    (_LVOrtAllocRequestA,a6)
  1786.         move.l    d0,JoinRequester
  1787.         beq.w    norequester
  1788.  
  1789.     ;get files to join
  1790.         movea.l    d0,a1
  1791.         lea    JoinFilename,a2
  1792.         lea    JoinGetTitle,a3
  1793.         lea    JoinGetTags,a0
  1794.         jsr    (_LVOrtFileRequestA,a6)
  1795.         move.l    d0,JoinFileList
  1796.         beq.w    .nofilelist
  1797.     ;change dir
  1798.         movea.l    JoinRequester,a0
  1799.  
  1800.         movea.l    DosBase,a6
  1801.         move.l    (rtfi_Dir,a0),d1
  1802.         move.l    #ACCESS_READ,d2
  1803.         jsr    (_LVOLock,a6)
  1804.         move.l    d0,JoinDirLock    ;store the lock
  1805.         move.l    d0,d1
  1806.         jsr    (_LVOCurrentDir,a6)
  1807.         move.l    d0,JoinOldDir
  1808.  
  1809. ;------------------------------------------------------
  1810.         movea.l    JoinFileList,a3    ;filelist
  1811.         lea    (join_errors,pc),a0
  1812.         clr.b    (a0)
  1813. .ex
  1814.         move.l    (rtfl_Name,a3),d0
  1815.         bsr.w    LOAD_FILE    ;IN:d0-filename  ;OUT: d0-adr. or 0 ;d1- len
  1816.         tst.l    d0
  1817.         beq.s    .nosuchfile
  1818.         lea    (fb,pc),a0    ;store buffer
  1819.         move.l    d0,(a0)
  1820.  
  1821.         bfclr    d1{0:16}
  1822.         bne.s    .nohiscores    ;too big to be hiscore file
  1823.         subq.w    #1,d1        ;file lenght
  1824.         bmi.s    .nohiscores    ;empty file
  1825.         movea.l    d0,a5
  1826.         movea.l    JoinPrefsBuf,a4
  1827.         bsr.w    GetMHS        ;extract the data
  1828.         tst.l    d0
  1829.         bne.s    .nohiscores
  1830.         bsr.w    Join2Scores
  1831.         st    ([MyPrefs],mhs_NewHiscore)
  1832.         clr.b    ValidHSText
  1833.     ;free file buffer
  1834. .freefile    movea.l    (fb,pc),a1
  1835.         bsr.w    FreeMemBlock
  1836.  
  1837. .next        tst.l    (a3)        ;rtfl_Next
  1838.         beq.s    .done        ;all examined?
  1839.         movea.l    (a3),a3        ;Next
  1840.         bra.s    .ex
  1841.  
  1842. .nosuchfile    lea    (join_errors,pc),a0
  1843.         st    (a0)
  1844.         lea    (examine_Text,pc),a0
  1845.         bsr.w    PrintText
  1846.         move.l    (rtfl_Name,a3),a0
  1847.         bsr.w    PrintText
  1848.         lea    (ERRNOFILE,pc),a0
  1849.         bsr.w    PrintText
  1850.         bra.s    .next
  1851. .nohiscores    lea    (join_errors,pc),a0
  1852.         st    (a0)
  1853.         lea    (examine_Text,pc),a0
  1854.         bsr.w    PrintText
  1855.         move.l    (rtfl_Name,a3),a0
  1856.         bsr.w    PrintText
  1857.         lea    (ERRNOSCORES,pc),a0
  1858.         bsr.w    PrintText
  1859.         bra.s    .freefile
  1860. ;-------------------------------------------
  1861. .done        movea.l    _ReqToolsBase,a6
  1862.         movea.l    JoinFileList,a0
  1863.         jsr    (_LVOrtFreeFileList,a6)
  1864.  
  1865.         movea.l    DosBase,a6
  1866.         move.l    JoinDirLock,d1
  1867.         jsr    (_LVOUnLock,a6)
  1868.  
  1869.         move.l    JoinOldDir,d1
  1870.         jsr    (_LVOCurrentDir,a6)
  1871.  
  1872. .nofilelist    movea.l    _ReqToolsBase,a6
  1873.         movea.l    JoinRequester,a1
  1874.         jsr    (_LVOrtFreeRequest,a6)
  1875.  
  1876.         movea.l    JoinPrefsBuf,a1
  1877.         bsr.w    FreeMemBlock
  1878.  
  1879.         tst.b    (join_errors,pc)
  1880.         beq.s    .noerr
  1881.         lea    (joinerr_Text,pc),a1
  1882.         lea    (joinerr_Button,pc),a2
  1883.         bsr.w    InformationReq
  1884. .noerr        bsr.w    mh_HiScores
  1885.         rts
  1886.  
  1887. norequester
  1888. fatalerror    lea    (jnm_Text,pc),a1
  1889.         lea    (jnm_Button,pc),a2
  1890.         bsr.w    InformationReq
  1891.         rts
  1892.  
  1893. ERRNOFILE    dc.b    9,'   ** no such file.',10,0
  1894. ERRNOSCORES    dc.b    9,'   ** not a Hi-Score file.',10,0
  1895.  
  1896. examine_Text    dc.b    'File: ',0
  1897. jnm_Text    dc.b    'Not enough memory.',0
  1898. jnm_Button    dc.b    'Continue',0
  1899. joinerr_Text    dc.b    'Some errors occured.',10
  1900.         dc.b    'See MineSweeper output window.',0
  1901. joinerr_Button    dc.b    'OK',0
  1902. join_errors    dc.b    0        ;BOOL
  1903.         cnop    0,4
  1904.  
  1905. ;----------------------------------------------------------------
  1906. COMPARE        MACRO
  1907.         move.w    (mhs_\1Time1,a0),d0    ;loaded time
  1908.         lea    (mhs_\1Name1,a0),a2
  1909.         bsr.s    .check\@
  1910.         move.w    (mhs_\1Time2,a0),d0
  1911.         lea    (mhs_\1Name2,a0),a2
  1912.         pea    (.exit\@,pc)
  1913. .check\@    cmp.w    (mhs_\1Time1,a1),d0    ;destination hiscores
  1914.         bhs.s    .try2nd\@
  1915.     ;insert d0,a2 to first place
  1916.         movem.l    d0/a2,-(sp)
  1917.         move.w    (mhs_\1Time1,a1),d0
  1918.         lea    (mhs_\1Name1,a1),a2
  1919.         bsr.s    .set2nd\@
  1920.         movem.l    (sp)+,d0/a2
  1921.         move.w    d0,(mhs_\1Time1,a1)
  1922.         lea    (mhs_\1Name1,a1),a3
  1923.         bra.s    .cpname\@
  1924.  
  1925. .try2nd\@    cmp.w    (mhs_\1Time2,a1),d0
  1926.         bhs.s    .trynext\@
  1927.     ;set d0,a2 to second place
  1928. .set2nd\@    move.w    d0,(mhs_\1Time2,a1)
  1929.         lea    (mhs_\1Name2,a1),a3
  1930. .cpname\@    moveq    #NAMELEN-1,d0
  1931. .cp\@        move.b    (a2)+,(a3)+        ;set new name
  1932.         dbra    d0,.cp\@
  1933.  
  1934. .trynext\@    rts
  1935. .exit\@
  1936.         ENDM
  1937.  
  1938. Join2Scores    movem.l    a0-a3,-(sp)
  1939.         movea.l    JoinPrefsBuf,a0
  1940.         movea.l    MyPrefs,a1
  1941.         COMPARE    Easy
  1942.         COMPARE    Normal
  1943.         COMPARE    Hard
  1944.         COMPARE    Profi
  1945.     ;now handle custom levels
  1946.  
  1947.     ;check 1st sour match 1st dest
  1948.     ;  yes
  1949.     ;    better 1st sour 1st dest
  1950.     ;         yes
  1951.     ;            copy 1st dest to 2nd dest
  1952.     ;            copy 1st sour to 1st dest
  1953.     ;            exit
  1954.     ;         no
  1955.     ;  no
  1956.  
  1957.     ; check2nd
  1958.  
  1959.     ;    check 1st sour match 2nd dest
  1960.     ;      yes
  1961.     ;         better 1st sour 2nd dest
  1962.     ;           yes
  1963.     ;              copy 1st sour to 2nd dest
  1964.     ;              exit
  1965.     ;           no
  1966.     ;      no
  1967.     ;  repeat all for 2nd sour
  1968.     ; exit
  1969.  
  1970. ;--------------------------------------------------
  1971. CHECKBETTER    MACRO    ;IN: sour pos., dest pos.
  1972.             ;OUT: Zero<=>True else false
  1973.     ;check \1 sour match \2 dest
  1974.         move.w    (mhs_CustomWidth\2,a1),d0
  1975.         beq.s    .matched\@    ;no custom defined yet
  1976.         cmp.w    (mhs_CustomWidth\1,a0),d0
  1977.         bne.s    .nomatchcb\@
  1978.         move.w    (mhs_CustomHeight\1,a0),d0
  1979.         cmp.w    (mhs_CustomHeight\2,a1),d0
  1980.         bne.s    .nomatchcb\@
  1981.         move.w    (mhs_CustomBombs\1,a0),d0
  1982.         cmp.w    (mhs_CustomBombs\2,a1),d0
  1983.         bne.s    .nomatchcb\@
  1984. .matched\@
  1985.     ;    better \1 sour than \2 dest?
  1986.         move.w    (mhs_CustomTime\1,a0),d0
  1987.         cmp.w    (mhs_CustomTime\2,a1),d0
  1988.         bhs.s    .nomatchcb\@
  1989.         moveq    #0,d0
  1990.         bra.s    .exit\@
  1991. .nomatchcb\@    moveq    #-1,d0
  1992. .exit\@
  1993.         ENDM
  1994. ;--------------------------------------------------
  1995. COPY        MACRO    ;IN: 1|2, sour data , 1|2, dest data
  1996.         move.w    mhs_CustomTime\1(\2),mhs_CustomTime\3(\4)
  1997.         move.w    mhs_CustomWidth\1(\2),mhs_CustomWidth\3(\4)
  1998.         move.w    mhs_CustomHeight\1(\2),mhs_CustomHeight\3(\4)
  1999.         move.w    mhs_CustomBombs\1(\2),mhs_CustomBombs\3(\4)
  2000.         movea.l    \2,a2    ;store regs
  2001.         movea.l    \4,a3
  2002.     ;copy the name
  2003.         lea    (mhs_CustomName\1,a2),a2
  2004.         lea    (mhs_CustomName\3,a3),a3
  2005. .cp\@        move.b    (a2)+,(a3)+
  2006.         bne.s    .cp\@
  2007.         ENDM
  2008. ;--------------------------------------------------
  2009. DOCUSTOM    MACRO    ;IN:  1|2 for 1st|2nd
  2010.         CHECKBETTER    \1,1
  2011.         bne.s    .check2nd\@
  2012.     ;matched        
  2013.         COPY    \1,a1,2,a1    ;works also with 2nd to 2nd
  2014.         COPY    \1,a0,\1,a1    ;        - "" -
  2015.         bra.w    .exitcust
  2016. .check2nd\@    CHECKBETTER    \1,2
  2017.         bne.s    .nomatch\@
  2018.         COPY    \1,a0,2,a1
  2019.         bra.w    .exitcust
  2020. .nomatch\@
  2021.         ENDM
  2022. ;--------------------------------------------------
  2023.         DOCUSTOM 1
  2024.         DOCUSTOM 2    ;bra.s    .exitcust
  2025.         moveq    #0,d0    ;just bytes
  2026. .exitcust
  2027.         movem.l    (sp)+,a0-a3
  2028.         rts
  2029.  
  2030. ;*****************************************************************
  2031. noWBLib_text    dc.b    '"workbench.library" V36+ required to iconify.',0
  2032. noWBLib_button    dc.b    'I see..',0
  2033. cantic_Text    dc.b    'Couldn',39,'t iconify.',0
  2034. cantic_Button    dc.b    'Continue',0
  2035. WBLibName    dc.b    'workbench.library',0
  2036. errunic_Text    dc.b    'Couldn',39,'t uniconify correctly.',10
  2037.         dc.b    'Some memory may be wasted.',0
  2038. errunic_Button    dc.b    'I see.',0
  2039.  
  2040. MinesMenuName
  2041. MinesPortName    dc.b    'MineSweeper',0
  2042.  
  2043.         cnop    0,4
  2044. WBLibBase    dc.l    0
  2045. MinesMsgPort    dc.l    0
  2046. MinesAppMenuItem dc.l    0
  2047.  
  2048. mh_Iconify
  2049.     ;open "workbench.library"
  2050.         movea.l    (EB,PC),a6
  2051.         lea    (WBLibName,pc),a1
  2052.         moveq    #MinWBVer,d0
  2053.         jsr    (_LVOOpenLibrary,a6)
  2054.         lea    (WBLibBase,pc),a0
  2055.         move.l    d0,(a0)
  2056.         bne.s    .ok
  2057.         lea    (noWBLib_text,pc),a1
  2058.         lea    (noWBLib_button,pc),a2
  2059.         bsr.w    InformationReq
  2060.         rts
  2061. .ok
  2062.         bsr.w    StopTimer
  2063.     ;set actual window size and position to tag list
  2064.     ;close the window
  2065.         bsr.w    ClearMenu
  2066.         bsr.w    CloseMyWindow
  2067.         clr.l    OldIDCMP
  2068.     ;close the screen
  2069.         bsr.w    FreeGfx
  2070.         bsr.w    FreeVisualInfo
  2071.         bsr.w    CloseMyScreen    ;also frees draw info
  2072.  
  2073.         pea    (.ret,pc)
  2074.         movea.l    MyPrefs,a0
  2075.         cmpi.b    #ICON_ICON,(mprf_Iconify,a0)
  2076.         beq.w    ic_AppIcon
  2077.         bra.w    ic_AppMenu
  2078. .ret        tst.l    d0
  2079.         bne.s    .iccont
  2080.         lea    (cantic_Text,pc),a1
  2081.         lea    (cantic_Button,pc),a2
  2082.         bsr.w    InformationReq
  2083.         bra.s    .skipwaitport
  2084. ;-----------------------------------
  2085. ;Now wait for a message either from another MineSweeper (that's why it
  2086. ;must be a public port)
  2087. ;or from AppMenu
  2088. ;-----------------------------------
  2089. .iccont
  2090.         movea.l    (EB,PC),a6
  2091.         movea.l    (MinesMsgPort,pc),a3    ;msgport
  2092. .waitloop    movea.l    a3,a0
  2093.         jsr    (_LVOWaitPort,a6)
  2094. .collectall    movea.l    a3,a0
  2095.         jsr    (_LVOGetMsg,a6)
  2096.         tst.l    d0
  2097.         beq.s    .waitloop    ;no more messages
  2098.  
  2099.         movea.l    d0,a1
  2100.         move.l    (am_ID,a1),d6
  2101. .notmine    jsr    (_LVOReplyMsg,a6)
  2102.         cmpi.l    #'MINE',d6    ;message from another MineSweeper,
  2103.                     ;or from appmenu-window-icon?
  2104.         bne.s    .collectall    ;unknown
  2105.  
  2106.         movea.l    Semaphore,a0
  2107.         jsr    (_LVOObtainSemaphore,a6)
  2108.     ;collect rest of possible messages
  2109. .getall        movea.l    a3,a0
  2110.         jsr    (_LVOGetMsg,a6)
  2111.         tst.l    d0
  2112.         bne.s    .getall
  2113.  
  2114.         pea    (.ret2,pc)
  2115.         movea.l    MyPrefs,a0
  2116.         cmpi.b    #ICON_ICON,(mprf_Iconify,a0)
  2117.         beq.w    ic_RemAppIcon
  2118.         bra.w    ic_RemAppMenu
  2119. .ret2
  2120.         tst.l    d0    ;ret. code from ic_RemApp....
  2121.         bne.s    .ok1    ;currently always TRUE (V39)
  2122.         lea    (errunic_Text,pc),a1
  2123.         lea    (errunic_Button,pc),a2
  2124.         bsr.w    InformationReq
  2125.  
  2126. .ok1        movea.l    (EB,PC),a6
  2127.         movea.l    Semaphore,a0
  2128.         jsr    (_LVOReleaseSemaphore,a6)
  2129. .skipwaitport
  2130.  
  2131. ic_ret        movea.l    (EB,PC),a6
  2132.         movea.l    (WBLibBase,pc),a1
  2133.         jsr    (_LVOCloseLibrary,a6)
  2134.  
  2135.         st    FromIconify
  2136.         lea    (12,sp),sp    ;rts,a2,d2
  2137.         clr.b    Pause
  2138.         bra.w    iconify_Return
  2139.  
  2140. ;----------------------------------------------------------
  2141. ic_AppIcon    ;*get icon
  2142.         movea.l    (EB,PC),a6
  2143.         lea    (IconName,pc),a1
  2144.         moveq    #MinIconVer,d0
  2145.         jsr    (_LVOOpenLibrary,a6)    ;"icon.library" V36
  2146.         lea    (IconBase,pc),a0
  2147.         move.l    d0,(a0)
  2148.         beq.s    .noiconlib
  2149.  
  2150.         lea    ProgramName,a0
  2151.         movea.l    (IconBase,pc),a6
  2152.         jsr    (_LVOGetDiskObjectNew,a6)    ;get "mines.info" or something
  2153.         lea    (diskObj,pc),a0
  2154.         move.l    d0,(a0)
  2155.         beq.s    .closelib        ;shouldn't happen...
  2156.  
  2157.         movea.l    (WBLibBase,pc),a6
  2158.         move.l    #'MINE',d0    ;id
  2159.         moveq    #0,d1        ;userdata
  2160.         lea    (ic_Name,pc),a0
  2161.         movea.l    (MinesMsgPort,pc),a1    ;msgport
  2162.         suba.l    a2,a2        ;lock
  2163.         movea.l    (diskObj,pc),a3    ;object
  2164.         suba.l    a4,a4        ;taglist
  2165.         jsr    (_LVOAddAppIconA,a6)
  2166.         lea    (AppIconPtr,pc),a0
  2167.         move.l    d0,(a0)
  2168.  
  2169.         move.l    d0,d2        ;store ret. code (0=fail)
  2170.         movea.l    (IconBase,pc),a6
  2171.         movea.l    (diskObj,pc),a0
  2172.         jsr    (_LVOFreeDiskObject,a6)
  2173.         move.l    d2,d0
  2174. .closelib    move.l    d0,-(sp)    ;store return code
  2175.         movea.l    (EB,PC),a6
  2176.         movea.l    (IconBase,pc),a1
  2177.         jsr    (_LVOCloseLibrary,a6)
  2178.         move.l    (sp)+,d0
  2179.         rts
  2180. .noiconlib    moveq    #0,d0
  2181.         rts
  2182.  
  2183. AppIconPtr    dc.l    0
  2184. ic_Name        dc.b    'MineSweeper',0
  2185.         cnop    0,4
  2186. ;-----------------------------------------------
  2187. ic_RemAppIcon    movea.l    (WBLibBase,pc),a6
  2188.         movea.l    (AppIconPtr,pc),a0
  2189.         jsr    (_LVORemoveAppIcon,a6)
  2190.         rts
  2191. ;----------------------------------------------------------
  2192. ic_AppMenu    ;OUT: d0 - 0=fail
  2193. ;Add MineSweeper to AppMenu******
  2194.         movea.l    (WBLibBase,pc),a6
  2195.         move.l    #'MINE',d0    ;id
  2196.         moveq    #0,d1        ;userdata
  2197.         lea    (MinesMenuName,pc),a0    ;menu text
  2198.         movea.l    (MinesMsgPort,pc),a1    ;msgport
  2199.         suba.l    a2,a2            ;taglist
  2200.         jsr    (_LVOAddAppMenuItemA,a6)
  2201.         lea    (MinesAppMenuItem,pc),a0
  2202.         move.l    d0,(a0)
  2203.         rts
  2204. ;-----------------------------------------------
  2205. ic_RemAppMenu    ;now remove me from AppMenu
  2206.         movea.l    (WBLibBase,pc),a6
  2207.         movea.l    (MinesAppMenuItem,pc),a0
  2208.         jsr    (_LVORemoveAppMenuItem,a6)    ;as far as I know,
  2209.         rts                    ;the result is always TRUE
  2210. ;*****************************************************************
  2211. OpenPublicPort
  2212.     ;create msg port
  2213.         movea.l    (EB,PC),a6
  2214.         jsr    (_LVOCreateMsgPort,a6)
  2215.         lea    (MinesMsgPort,pc),a0
  2216.         move.l    d0,(a0)
  2217.         beq.s    .ret
  2218.         movea.l    d0,a1
  2219.         move.b    #1,(LN_PRI,a1)    ;priority=1
  2220.         lea    (MinesPortName,pc),a0
  2221.         move.l    a0,(LN_NAME,a1)
  2222.         jsr    (_LVOAddPort,a6) ;make it public (IN: a1-port OUT: NIL)
  2223. .ret        rts
  2224. ClosePublicPort
  2225.     ;remove port from public list
  2226.         movea.l    (EB,PC),a6
  2227.         movea.l    (MinesMsgPort,pc),a3    ;msgport
  2228.         movea.l    a3,a1
  2229.         jsr    (_LVORemPort,a6)    ;IN: a1-port OUT:NIL
  2230.         movea.l    a3,a0
  2231.         jsr    (_LVODeleteMsgPort,a6)    ;IN:a0-port OUT:NIL
  2232.         rts
  2233. ;*****************************************************************
  2234. ;**Open libraries and/or display errors.
  2235. OpenReqTools    movea.l    (EB,PC),a6        ;This must be called at first!
  2236.         moveq    #MinReqToolsVer,d0
  2237.         lea    ReqToolsName,a1    ;"reqtools.library"
  2238.         jsr    (_LVOOpenLibrary,a6)
  2239.         move.l    d0,_ReqToolsBase
  2240.         bne.s    .exit
  2241.         bsr.s    OpenDos
  2242.         beq.s    .exit        ;no dos.library (!?)
  2243.         lea    noreq_Text,a0
  2244.         bsr.w    PrintText
  2245.         moveq    #0,d0        ;set zero flag
  2246. .exit        rts
  2247.  
  2248. OpenIntuition    movea.l    (EB,PC),a6        ;open "intuition.library"
  2249.         moveq    #MinIntuiVer,d0
  2250.         lea    IntuiName,a1
  2251.         jsr    (_LVOOpenLibrary,a6)
  2252.         move.l    d0,IntuiBase
  2253.         bne.s    .exit
  2254.         lea    nointui_Text,a1
  2255.         lea    nointui_Button,a2
  2256.         bsr.w    InformationReq
  2257.         moveq    #0,d0
  2258. .exit        rts
  2259.  
  2260. OpenGraphics    movea.l    (EB,PC),a6        ;open "graphics.library"
  2261.         moveq    #MinGfxVer,d0
  2262.         lea    GfxName,a1
  2263.         jsr    (_LVOOpenLibrary,a6)
  2264.         move.l    d0,_GfxBase
  2265.         bne.s    .exit
  2266.         lea    nogfx_Text,a1
  2267.         lea    nogfx_Button,a2
  2268.         bsr.w    InformationReq
  2269.         moveq    #0,d0
  2270. .exit        rts
  2271.  
  2272. OpenDos        movea.l    (EB,PC),a6        ;"dos.library"
  2273.         moveq    #MinDosVer,d0
  2274.         lea    DosName,a1
  2275.         jsr    (_LVOOpenLibrary,a6)
  2276.         move.l    d0,DosBase
  2277.         bne.s    .exit
  2278.         lea    nodos_Text,a1
  2279.         lea    nodos_Button,a2
  2280.         bsr.w    InformationReq
  2281.         moveq    #0,d0
  2282. .exit        rts
  2283.  
  2284. OpenGadtools    movea.l    (EB,PC),a6        ;"gadtools.library"
  2285.         moveq    #MinGadToolsVer,d0
  2286.         lea    GadtoolsName,a1
  2287.         jsr    (_LVOOpenLibrary,a6)
  2288.         move.l    d0,GadtoolsBase
  2289.         bne.s    .exit
  2290.         lea    nogad_Text,a1
  2291.         lea    nogad_Button,a2
  2292.         bsr.w    InformationReq
  2293.         moveq    #0,d0
  2294. .exit        rts
  2295.  
  2296. OpenUtility    movea.l    (EB,PC),a6        ;open "utility.library"
  2297.         moveq    #MinUtilityVer,d0
  2298.         lea    UtilityName,a1
  2299.         jsr    (_LVOOpenLibrary,a6)
  2300.         move.l    d0,UtilityBase
  2301.         bne.s    .exit
  2302.         lea    noutility_Text,a1
  2303.         lea    noutility_Button,a2
  2304.         bsr.w    InformationReq
  2305.         moveq    #0,d0
  2306. .exit        rts
  2307.  
  2308. ;**********************************************************
  2309. GetStartDirs    clr.l    OldDirectory
  2310.         movea.l    DosBase,a6
  2311.         move.l    WBmessage,d0    ;from WB?
  2312.         beq.s    .cli
  2313.     ;WB version
  2314.         movea.l    d0,a0
  2315.         movea.l    (sm_ArgList,a0),a0
  2316.         movea.l    (wa_Name,a0),a1
  2317.         lea    ProgramName,a2
  2318. .cp        move.b    (a1)+,(a2)+
  2319.         bne.s    .cp
  2320.         move.l    (wa_Lock,a0),d1
  2321.         move.l    d1,ProgDir
  2322. .cd        jsr    (_LVOCurrentDir,a6)
  2323.         move.l    d0,OldDirectory
  2324.         rts
  2325.  
  2326.     ;*cli version
  2327. .cli        move.l    #ProgramName,d1
  2328.         move.l    #PROGNAMELEN,d2
  2329.         jsr    (_LVOGetProgramName,a6)
  2330.         tst.l    d0
  2331.         beq.s    .setmyname
  2332. .getdir        jsr    (_LVOGetProgramDir,a6)
  2333.         move.l    d0,ProgDir
  2334.         rts
  2335.  
  2336. .setmyname    lea    (defaultName,pc),a0
  2337.         lea    ProgramName,a1
  2338. .cp1        move.b    (a0)+,(a1)+
  2339.         bne.s    .cp1
  2340.         bra.s    .getdir
  2341.  
  2342. defaultName    dc.b    'Mines',0
  2343.         cnop    0,4
  2344. ;------------------------------------------------------
  2345. FreeStartDir    move.l    OldDirectory,d1
  2346.         beq.s    .exit
  2347.         movea.l    DosBase,a6
  2348.         jsr    (_LVOCurrentDir,a6)
  2349. .exit        rts
  2350. ;**********************************************************
  2351. GetOutput    ;IN:DosBase
  2352.         ;out: d0=output
  2353.         movem.l    d1/d2/a0/a1/a6,-(sp)
  2354.         lea    (myOutput,pc),a6
  2355.         move.l    a6,d1
  2356.         move.l    #MODE_NEWFILE,d2
  2357.         movea.l    DosBase,a6
  2358.         jsr    (_LVOOpen,a6)
  2359.         lea    (MyOut,pc),a0
  2360.         move.l    d0,(a0)
  2361.         movem.l    (sp)+,d1/d2/a0/a1/a6
  2362.         rts
  2363. myOutput    dc.b    'CON://600/150/MineSweeper output window/CLOSE/AUTO/SIMPLE/INACTIVE/WAIT',0
  2364.         cnop    0,4
  2365. MyOut        dc.l    0
  2366. ;**********************************************************
  2367. PrintText    ;IN: a0-null terminated string
  2368.         movem.l    d0-d3/a0/a1/a6,-(sp)
  2369.         movea.l    DosBase,a6
  2370.         move.l    (MyOut,pc),d1        ;identif. vystupu
  2371.         bne.s    .ok
  2372.         bsr.s    GetOutput
  2373.         move.l    d0,d1
  2374.         beq.s    .exit
  2375. .ok        moveq    #0,d3        ;lenght
  2376.         move.l    a0,d2
  2377. .1        tst.b    (a0)+
  2378.         beq.s    .endtext
  2379.         addq.l    #1,d3
  2380.         bra.s    .1
  2381. .endtext    jsr    (_LVOWrite,a6)    ;I don't care about the result
  2382. .exit        movem.l    (sp)+,d0-d3/a0/a1/a6
  2383.         rts
  2384. ;*****************************************************************
  2385. InitPF        ;Two fields are allocated:
  2386.         ;1. numbers, bombs, empty gadgets, noflags
  2387.         ;2. 0 - empty gadget
  2388.         ;   1 - pressed gadgets
  2389.         ;   2 - flag
  2390.  
  2391.         move.l    PFAdr,d1
  2392.         beq.s    .nopf
  2393.         move.w    PFWidth,d0
  2394.         mulu.w    PFHeight,d0
  2395.         cmp.w    PFSize,d0
  2396.         beq.s    .allocated
  2397.     ;first free last PF
  2398.         movea.l    d1,a1
  2399.         bsr.w    FreeMemBlock
  2400. .nopf
  2401.     ;alloc new
  2402.         move.w    PFWidth,d0
  2403.         mulu.w    PFHeight,d0
  2404.         move.l    d0,d1        ;check the size (max 65535)
  2405.         andi.l    #$ffff0000,d1
  2406.         bne.w    .ipf_toobig
  2407.  
  2408.         move.w    d0,PFSize
  2409.         ext.l    d0
  2410.         move.l    d0,d2        ;store
  2411.         add.l    d0,d0        ;allocate 2 fields
  2412.         moveq    #0,d1
  2413.         bsr.w    ADDALLOC
  2414.         move.l    d0,PFAdr
  2415.         beq.w    .ipf_error
  2416.  
  2417.     ;alloc buffer for seedfill
  2418.         move.l    SeedFillStack,d0
  2419.         beq.s    .noyet
  2420.         movea.l    d0,a1
  2421.         bsr.w    FreeMemBlock
  2422. .noyet        move.w    PFWidth,d0
  2423.         mulu.w    PFHeight,d0
  2424.         mulu.w    #12,d0        ;12 bytes per button
  2425.         addi.l    #24,d0        ;to be sure
  2426.         move.l    d0,d6    ;store
  2427.         moveq    #0,d1
  2428.         bsr.w    ADDALLOC
  2429.         move.l    d0,SeedFillStack
  2430.         beq.w    .ipf_error
  2431.         add.l    d6,d0    ;end of the area
  2432.         move.l    d0,SeedFillSP    ;ptr to the stack
  2433.  
  2434.     ;**fill it with values
  2435. .allocated    ;first clear both fields
  2436.         movea.l    PFAdr,a0
  2437.         move.w    PFSize,d0
  2438.         add.w    d0,d0        ;both
  2439.         subq.w    #1,d0
  2440. .clr        clr.b    (a0)+
  2441.         dbra    d0,.clr
  2442.     ;**bombs
  2443.         movea.l    IntuiBase,a0
  2444.         move.l    (ib_Micros,a0),RndSeed
  2445.  
  2446.     ;use SeedFillStack to generate random values
  2447.         movea.l    SeedFillStack,a0
  2448.  
  2449.         move.w    PFWidth,d3
  2450.         move.w    PFHeight,d4
  2451.         subq.w    #1,d3
  2452.         subq.w    #1,d4
  2453.         moveq    #1,d1        ;start for y
  2454. .yloop        moveq    #1,d0        ;start for x
  2455. .xloop        move.w    d1,d2        ;position in the PF
  2456.         mulu.w    PFWidth,d2
  2457.         add.w    d0,d2
  2458.         move.w    d2,(a0)+
  2459.         addq.w    #1,d0        ;next x
  2460.         cmp.w    d3,d0        ;PFWidth-1
  2461.         bne.s    .xloop
  2462.         addq.w    #1,d1        ;next y
  2463.         cmp.w    d4,d1        ;PFHeight-1
  2464.         bne.s    .yloop
  2465.  
  2466.         movea.l    PFAdr,a0
  2467.         movea.l    SeedFillStack,a1
  2468.         move.w    PFBombs,d7
  2469.         subq.w    #1,d7
  2470.         move.w    PFWidth,d0
  2471.         move.w    PFHeight,d3
  2472.         subq.w    #2,d0
  2473.         subq.w    #2,d3
  2474.         mulu.w    d0,d3        ;range for Rand
  2475.         subq.w    #1,d3
  2476.  
  2477. .next
  2478.         move.w    d3,d0        ;range
  2479.         addq.w    #1,d0
  2480.         bsr.w    Rand
  2481.         move.w    (a1,d0.w*2),d1    ;get PF pos. of the bomb
  2482.         move.w    (a1,d3.w*2),(a1,d0.w*2)    ;and move last item to current
  2483.         move.b    #mgg_Bomb/4,(a0,d1.w)
  2484.         subq.w    #1,d3        ;decrease range
  2485.         dbra    d7,.next
  2486.         addq.w    #1,d3
  2487.         move.w    d3,MaxRandRange
  2488.     ;**numbers
  2489.         movea.l    PFAdr,a0
  2490.         moveq    #1,d1        ;ypos
  2491.         move.w    PFWidth,d2    ;maxx
  2492.         move.w    PFHeight,d3    ;maxy
  2493. .looplines    moveq    #1,d0        ;xpos
  2494. .loopcolumns    move.w    d1,d4
  2495.         mulu.w    d2,d4
  2496.         add.w    d0,d4
  2497.         cmpi.b    #mgg_Bomb/4,(a0,d4.w)
  2498.         bne.s    .no
  2499.         moveq    #1,d7
  2500.         bsr.w    AddAround
  2501.  
  2502. .no        addq.w    #1,d0        ;next column
  2503.         cmp.w    d2,d0
  2504.         bne.s    .loopcolumns
  2505.         addq.w    #1,d1        ;next line
  2506.         cmp.w    d3,d1
  2507.         bne.w    .looplines
  2508.     ;fill the border to range an area for seedfill
  2509.         movea.l    PFAdr,a0
  2510.         adda.w    PFSize,a0
  2511.         movea.l    a0,a1
  2512.         move.w    PFWidth,d0
  2513.         move.w    d0,d1
  2514.         mulu.w    PFHeight,d1
  2515.         adda.w    d1,a1
  2516.         suba.w    d0,a1
  2517.         subq.w    #1,d0
  2518. .fb1        move.b    #1,(a0)+
  2519.         move.b    #1,(a1)+
  2520.         dbra    d0,.fb1
  2521.         movea.l    PFAdr,a0
  2522.         adda.w    PFSize,a0
  2523.         move.b    #1,(a0)    ;first line, first col.
  2524.         move.w    PFWidth,d0
  2525.         subq.w    #1,d0
  2526.         adda.w    d0,a0
  2527.         addq.w    #1,d0
  2528.         move.w    PFHeight,d1
  2529.         subq.w    #2,d1
  2530. .fb2        move.b    #1,(a0)    ;prev. line, last col.
  2531.         move.b    #1,(1,a0)    ;next line, first col.
  2532.         adda.w    d0,a0
  2533.         dbra    d1,.fb2
  2534.         move.b    #1,(a0)        ;last line, last col.
  2535.         rts
  2536.  
  2537. .ipf_error    lea    nopf_Text,a1
  2538.         lea    nopf_Button,a2
  2539.         bsr.w    InformationReq
  2540.         rts
  2541. .ipf_toobig    lea    pfbig_Text,a1
  2542.         lea    pfbig_Button,a2
  2543.         bsr.w    InformationReq
  2544.         clr.l    PFAdr
  2545.         rts
  2546. ;*****************************************************************
  2547.     ;increase all free items next to this
  2548. AddAround    ;IN: a0-PFAdr, d2-PFWidth, d4-offset, d7- value to add
  2549.         move.w    d4,-(sp)
  2550.         cmpi.b    #mgg_Bomb/4,(-1,a0,d4.w)
  2551.         beq.s    .0
  2552.         add.b    d7,(-1,a0,d4.w)    ;l
  2553.  
  2554. .0        cmpi.b    #mgg_Bomb/4,(1,a0,d4.w)
  2555.         beq.s    .1
  2556.         add.b    d7,(1,a0,d4.w)    ;r
  2557.  
  2558. .1        sub.w    d2,d4
  2559.  
  2560.         cmpi.b    #mgg_Bomb/4,(a0,d4.w)
  2561.         beq.s    .2
  2562.         add.b    d7,(a0,d4.w)    ;u
  2563. .2        cmpi.b    #mgg_Bomb/4,(-1,a0,d4.w)
  2564.         beq.s    .3
  2565.         add.b    d7,(-1,a0,d4.w)    ;ul
  2566. .3        cmpi.b    #mgg_Bomb/4,(1,a0,d4.w)
  2567.         beq.s    .4
  2568.         add.b    d7,(1,a0,d4.w)    ;ur
  2569.  
  2570. .4        add.w    d2,d4
  2571.         add.w    d2,d4
  2572.  
  2573.         cmpi.b    #mgg_Bomb/4,(a0,d4.w)
  2574.         beq.s    .5
  2575.         add.b    d7,(a0,d4.w)    ;d
  2576. .5        cmpi.b    #mgg_Bomb/4,(-1,a0,d4.w)
  2577.         beq.s    .6
  2578.         add.b    d7,(-1,a0,d4.w)    ;dl
  2579. .6        cmpi.b    #mgg_Bomb/4,(1,a0,d4.w)
  2580.         beq.s    .7
  2581.         add.b    d7,(1,a0,d4.w)    ;dr
  2582. .7        move.w    (sp)+,d4
  2583.         rts
  2584. ;*****************************************************************
  2585.     ;get num. of items around
  2586. GetAround    ;IN: a0-PFAdr, d1-num. to check, d2-PFWidth, d4-offset
  2587.         ;OUT: d0-num.
  2588.         move.w    d4,-(sp)
  2589.         clr.b    d0
  2590.         cmp.b    (-1,a0,d4.w),d1
  2591.         bne.s    .0
  2592.         addq.b    #1,d0    ;l
  2593.  
  2594. .0        cmp.b    (1,a0,d4.w),d1
  2595.         bne.s    .1
  2596.         addq.b    #1,d0    ;r
  2597.  
  2598. .1        sub.w    d2,d4
  2599.  
  2600.         cmp.b    (a0,d4.w),d1
  2601.         bne.s    .2
  2602.         addq.b    #1,d0    ;u
  2603. .2        cmp.b    (-1,a0,d4.w),d1
  2604.         bne.s    .3
  2605.         addq.b    #1,d0    ;ul
  2606. .3        cmp.b    (1,a0,d4.w),d1
  2607.         bne.s    .4
  2608.         addq.b    #1,d0    ;ur
  2609.  
  2610. .4        add.w    d2,d4
  2611.         add.w    d2,d4
  2612.  
  2613.         cmp.b    (a0,d4.w),d1
  2614.         bne.s    .5
  2615.         addq.b    #1,d0    ;d
  2616. .5        cmp.b    (-1,a0,d4.w),d1
  2617.         bne.s    .6
  2618.         addq.b    #1,d0    ;dl
  2619. .6        cmp.b    (1,a0,d4.w),d1
  2620.         bne.s    .7
  2621.         addq.b    #1,d0    ;dr
  2622. .7        move.w    (sp)+,d4
  2623.         rts
  2624. ;*****************************************************************
  2625.     ;IN: d0.w = range
  2626. Rand        movem.l    d4/d5,-(sp)
  2627.         move.w  d0,d5
  2628.         beq.s    .exit
  2629.         move.w  d5,d4
  2630.         subq.w  #1,d4
  2631.         move.l  RndSeed,d0
  2632. .loop        add.l    d0,d0
  2633.         bhi.s    .2
  2634.         eor.l    #$1d872b41,d0
  2635. .2        lsr.w    #1,d4
  2636.         bne.s    .loop
  2637.  
  2638.         move.l    d0,RndSeed
  2639.         tst.w    d5
  2640.         bne.s    .3
  2641.         swap    d0
  2642.         bra.s    .4
  2643. .3        mulu    d5,d0
  2644. .4        clr.w    d0
  2645.         swap    d0
  2646. .exit        movem.l    (sp)+,d4/d5
  2647.         rts
  2648. ;*****************************************************************
  2649. GetButtonSizes
  2650.     ;get rast. font size first
  2651.         move.l    WinFont,d0
  2652.         bne.s    .setsize
  2653.         moveq    #12,d0
  2654.         moveq    #12,d1
  2655.         bra.s    .skip
  2656. .setsize    movea.l    d0,a0
  2657.         move.w    (tf_XSize,a0),d0
  2658.         move.w    (tf_YSize,a0),d1
  2659.         addq.w    #4,d0
  2660.         addq.w    #4,d1
  2661. .skip
  2662.         cmpi.w    #BUTMINX+4,d0
  2663.         bge.s    .ok1
  2664.         move.w    #BUTMINX+4,d0
  2665. .ok1        cmpi.w    #BUTMINY+2,d1
  2666.         bge.s    .ok2
  2667.         move.w    #BUTMINY+2,d1
  2668. .ok2
  2669.     ;**get resolution and make buttons square
  2670.         movea.l    MyDrawInfo,a0
  2671.         move.w    (dri_ResolutionX,a0),d2
  2672.         move.w    (dri_ResolutionY,a0),d3
  2673.         muls.w    d2,d0
  2674.         muls.w    d3,d1
  2675.         cmp.l    d0,d1
  2676.         blt.s    .d1less
  2677.         move.l    d1,d0
  2678. .d1less        move.l    d0,d1
  2679.  
  2680.         divs.w    d2,d0
  2681.         divs.w    d3,d1
  2682.         move.w    d0,ButtWidth
  2683.         move.w    d1,ButtHeight
  2684.         rts
  2685. ;**************************************************************************
  2686. GetVisualInfo    movea.l    GadtoolsBase,a6
  2687.         movea.l    MyScreen,a0
  2688.         suba.l    a1,a1        ;no tags
  2689.         jsr    (_LVOGetVisualInfoA,a6)
  2690.         move.l    d0,VisualInfo        ;check this result!
  2691.         move.l    d0,dbb_TagList1+4
  2692.         move.l    d0,dbb_TagList2+4
  2693.         rts
  2694. FreeVisualInfo    movea.l    GadtoolsBase,a6
  2695.         movea.l    VisualInfo,a0        ;may be NULL
  2696.         jsr    (_LVOFreeVisualInfo,a6)
  2697.         rts
  2698. ;**************************************************************************
  2699. WritePlanes    ;IN:a0- ptr to bm_Planes, a1-rawgfx ptr.
  2700.         moveq    #3,d0
  2701. .write        move.l    a1,(a0)+
  2702.         lea    (BUTNEXTPLANE,a1),a1
  2703.         dbra    d0,.write
  2704.         rts
  2705. ;----------------------------------------------
  2706. SETGFX        MACRO
  2707.         lea    bm_Planes+bmap\1,a0
  2708.         lea    raw\1,a1
  2709.         bsr.w    WritePlanes
  2710.         ENDM
  2711. SETMGFX        MACRO
  2712.         lea    bm_Planes+bmap\1,a0
  2713.         lea    rawMagic\1,a1
  2714.         bsr.w    WritePlanes
  2715.         ENDM
  2716. ;----------------------------------------------
  2717. CreateGfx    ;create button-bitmaps
  2718.     ;first set type of gfx (Standard/MagicWB)
  2719.         tst.b    ([MyPrefs],mprf_GfxType)
  2720.         beq.s    .standard
  2721.         SETMGFX    Flag
  2722.         SETMGFX    NoFlag
  2723.         SETMGFX    Bomb
  2724.         SETMGFX    Blowed
  2725.     ;set planepick/onoff for numbers
  2726.         move.b    #%11,img_Number+ig_PlanePick
  2727.         bra.s    .skipset
  2728.  
  2729. .standard    SETGFX    Flag
  2730.         SETGFX    NoFlag
  2731.         SETGFX    Bomb
  2732.         SETGFX    Blowed
  2733. .skipset
  2734.  
  2735.     ;**allocate MGG struct. and a RastPort structure
  2736.         move.l    #mgg_SIZEOF+rp_SIZEOF,d0
  2737.         moveq    #0,d1
  2738.         bsr.w    ADDALLOC
  2739.         move.l    d0,MGGfx
  2740.         beq.w    creategfx_error
  2741.  
  2742.     ;**allocate bitmaps
  2743.         movea.l    MGGfx,a3
  2744.  
  2745.         movea.l    MyScreen,a2
  2746.         movea.l    (sc_RastPort+rp_BitMap,a2),a2    ;friend bitmap
  2747.  
  2748.         movea.l    _GfxBase,a6
  2749.         moveq    #GADBPLNUM-1,d7
  2750.  
  2751. .loop        move.w    ButtWidth,d0
  2752.         ext.l    d0
  2753.         move.w    ButtHeight,d1
  2754.         ext.l    d1
  2755.         moveq    #BUTMAXBPL,d2
  2756.         moveq    #BMF_CLEAR,d3
  2757.         movea.l    a2,a0        ;friend bitmap
  2758.         jsr    (_LVOAllocBitMap,a6)    ;V39
  2759.         move.l    d0,(a3)+
  2760.         dbeq    d7,.loop
  2761.         beq.w    creategfx_error
  2762.  
  2763.         movea.l    MGGfx,a2
  2764.         lea    (mgg_SIZEOF,a2),a3    ;my rast port
  2765.  
  2766.         movea.l    _GfxBase,a6
  2767.         movea.l    a3,a1
  2768.         jsr    (_LVOInitRastPort,a6)    ;initialize my rastport
  2769.         move.l    WinFont,d0
  2770.         beq.s    .nofont
  2771.         movea.l    a3,a1        ;rp
  2772.         movea.l    d0,a0        ;TextFont
  2773.         jsr    (_LVOSetFont,a6)
  2774. .nofont
  2775.     ;**now comes the main part
  2776.     ;*I'll set each bitmap to MyRP and draw the gfx to it
  2777.     ;a3:my rp
  2778.  
  2779.     ;1. draw bevelled boxes (empty gadget etc.)
  2780.         movea.l    MGGfx,a5
  2781.         movea.l    a3,a0    ;rp
  2782.         moveq    #0,d0    ;x
  2783.         move.l    d0,d1    ;y
  2784.         move.w    ButtWidth,d2
  2785.         ext.l    d2
  2786.         move.w    ButtHeight,d3
  2787.         ext.l    d3
  2788.         lea    dbb_TagList1,a1
  2789.         movea.l    GadtoolsBase,a6
  2790.  
  2791.         movem.l    d0/d1/a0/a1,-(sp)    ;(-)
  2792.         move.w    #mgg_NumOfNormal-1,d7
  2793.         moveq    #0,d6
  2794. .loopn        movem.l    (sp),d0/d1/a0/a1    ;restore damaged regs.
  2795.         move.l    (mgg_Empty,a5,d6.w),(rp_BitMap,a3)    ;set bitmap
  2796.         jsr    (_LVODrawBevelBoxA,a6)    ;draw to my bitmap
  2797.         addq.w    #4,d6    ;next bmap
  2798.         dbra    d7,.loopn
  2799.         movem.l    (sp)+,d0/d1/a0/a1    ;(+)
  2800.  
  2801.     ;2. recessed bevelled boxes
  2802.         movea.l    MGGfx,a5
  2803.         move.l    (mgg_EmptyRecessed,a5),(rp_BitMap,a3)    ;set bitmap
  2804.         movea.l    a3,a0    ;rp
  2805.         moveq    #0,d0    ;x
  2806.         move.l    d0,d1    ;y
  2807.         move.w    ButtWidth,d2
  2808.         ext.l    d2
  2809.         move.w    ButtHeight,d3
  2810.         ext.l    d3
  2811.         lea    dbb_TagList2,a1
  2812.         movea.l    GadtoolsBase,a6
  2813.  
  2814.         movem.l    d0/d1/a0/a1,-(sp)    ;(-)
  2815.         move.w    #mgg_NumOfRecessed-1,d7
  2816.         moveq    #0,d6
  2817. .loopr        movem.l    (sp),d0/d1/a0/a1    ;restore damaged regs.
  2818.         move.l    (mgg_EmptyRecessed,a5,d6.w),(rp_BitMap,a3)    ;set bitmap
  2819.         jsr    (_LVODrawBevelBoxA,a6)    ;draw to my bitmap
  2820.         addq.w    #4,d6    ;next bmap
  2821.         dbra    d7,.loopr
  2822.         movem.l    (sp)+,d0/d1/a0/a1    ;(+)
  2823.  
  2824.     ;3. 4. 5.  Flag, NoFlag, Bomb,Blowed bomb
  2825.     ;*Copy each gfx from it's bmap to "(mgg_xxxx,a5) bmap"
  2826.     ;first fill the background with EXTRABACKCOLOR
  2827.         movea.l    MGGfx,a5
  2828.         movea.l    _GfxBase,a6
  2829.  
  2830.         movea.l    a3,a1        ;rp
  2831.         moveq    #EXTRABACKCOLOR,d0
  2832.         jsr    (_LVOSetAPen,a6)
  2833.         moveq    #2,d0
  2834.         moveq    #1,d1
  2835.         move.w    ButtWidth,d2
  2836.         subq.w    #3,d2
  2837.         ext.l    d2
  2838.         move.w    ButtHeight,d3
  2839.         subq.w    #2,d3
  2840.         ext.l    d3
  2841.         movem.l    d0/d1,-(sp)    ;(-)
  2842.         move.l    (mgg_Flag,a5),(rp_BitMap,a3)
  2843.         movea.l    a3,a1
  2844.         jsr    (_LVORectFill,a6)
  2845.         movem.l    (sp),d0/d1
  2846.         move.l    (mgg_NoFlag,a5),(rp_BitMap,a3)
  2847.         movea.l    a3,a1
  2848.         jsr    (_LVORectFill,a6)
  2849.         movem.l    (sp),d0/d1
  2850.         move.l    (mgg_Bomb,a5),(rp_BitMap,a3)
  2851.         movea.l    a3,a1
  2852.         jsr    (_LVORectFill,a6)
  2853.  
  2854.         tst.b    ([MyPrefs],mprf_GfxType)
  2855.         beq.s    .std
  2856.         moveq    #BLOWEDBACKMAG,d0
  2857.         bra.s    .000
  2858. .std        moveq    #BLOWEDBACKSTD,d0
  2859. .000        movea.l    a3,a1        ;rp
  2860.         jsr    (_LVOSetAPen,a6)
  2861.         movem.l    (sp),d0/d1
  2862.         move.l    (mgg_Blowed,a5),(rp_BitMap,a3)
  2863.         movea.l    a3,a1
  2864.         jsr    (_LVORectFill,a6)
  2865.         movem.l    (sp)+,d0/d1    ;(+)
  2866.  
  2867.         tst.b    ([MyPrefs],mprf_ScaleGfx)
  2868.         beq.s    .notscale
  2869.     ;*****scale bitmaps
  2870.         lea    bitScaleArgs,a0
  2871.         clr.w    (bsa_SrcX,a0)
  2872.         clr.w    (bsa_SrcY,a0)
  2873.         move.w    #2,(bsa_DestX,a0)
  2874.         move.w    #1,(bsa_DestY,a0)
  2875.         move.w    #BUTMINX,(bsa_SrcWidth,a0)
  2876.         move.w    #BUTMINY,(bsa_SrcHeight,a0)
  2877.         clr.l    (bsa_Flags,a0)
  2878.     ;get denominators and numerators
  2879.     ;WIDTH
  2880.         move.w    ButtWidth,d0
  2881.         move.w    #BUTMINX,d1
  2882.         subq.w    #4,d0        ;dest. width
  2883.         move.l    #16383,d2
  2884.         divu.w    d0,d2
  2885.         mulu.w    d2,d0        ;x-numerator
  2886.         mulu.w    d2,d1        ;x-denominator
  2887.         move.w    d0,(bsa_XDestFactor,a0)
  2888.         move.w    d1,(bsa_XSrcFactor,a0)
  2889.     ;HEIGHT
  2890.         move.w    ButtHeight,d0
  2891.         move.w    #BUTMINY,d1
  2892.         subq.w    #2,d0        ;dest. height
  2893.         move.l    #16383,d2
  2894.         divu.w    d0,d2
  2895.         mulu.w    d2,d0        ;y-numerator
  2896.         mulu.w    d2,d1        ;y-denominator
  2897.         move.w    d0,(bsa_YDestFactor,a0)
  2898.         move.w    d1,(bsa_YSrcFactor,a0)
  2899.  
  2900.     ;--Flag
  2901.     ;    lea    bitScaleArgs,a0
  2902.         move.l    #bmapFlag,(bsa_SrcBitMap,a0)    ;SrcBitMap
  2903.         movea.l    (mgg_Flag,a5),(bsa_DestBitMap,a0)    ;DstBitBap
  2904.         jsr    (_LVOBitMapScale,a6)
  2905.     ;--NoFlag
  2906.         lea    bitScaleArgs,a0
  2907.         move.l    #bmapNoFlag,(bsa_SrcBitMap,a0)    ;SrcBitMap
  2908.         movea.l    (mgg_NoFlag,a5),(bsa_DestBitMap,a0)    ;DstBitBap
  2909.         jsr    (_LVOBitMapScale,a6)
  2910.     ;--Bomb
  2911.         lea    bitScaleArgs,a0
  2912.         move.l    #bmapBomb,(bsa_SrcBitMap,a0)    ;SrcBitMap
  2913.         movea.l    (mgg_Bomb,a5),(bsa_DestBitMap,a0)    ;DstBitBap
  2914.         jsr    (_LVOBitMapScale,a6)
  2915.     ;--Blowed
  2916.         lea    bitScaleArgs,a0
  2917.         move.l    #bmapBlowed,(bsa_SrcBitMap,a0)    ;SrcBitMap
  2918.         movea.l    (mgg_Blowed,a5),(bsa_DestBitMap,a0)    ;DstBitBap
  2919.         jsr    (_LVOBitMapScale,a6)
  2920.  
  2921.         bra.s    .skipnotscale
  2922. .notscale    ;center gfx in dest bitmap
  2923.         move.w    ButtWidth,d2
  2924.         asr.w    #1,d2        ;/2
  2925.         move.w    #BUTMINX,d0
  2926.         move.w    d0,d4        ;size x
  2927.         asr.w    #1,d0
  2928.         sub.w    d0,d2        ;dest x
  2929.         move.w    ButtHeight,d3
  2930.         asr.w    #1,d3
  2931.         move.w    #BUTMINY,d0
  2932.         move.w    d0,d5        ;size y
  2933.         asr.w    #1,d0
  2934.         sub.w    d0,d3        ;dest y
  2935.         ext.l    d2        ;to follow recommendations
  2936.         ext.l    d3
  2937.         ext.l    d4
  2938.         ext.l    d5
  2939.         moveq    #0,d0        ;sour x
  2940.         move.l    d0,d1        ;sour y
  2941.         move.l    #$c0,d6        ;miniterm
  2942.         moveq    #-1,d7        ;mask
  2943.         suba.l    a2,a2        ;TempA
  2944.  
  2945.         movem.l    d0/d1,-(sp)    ;store (-)
  2946.         lea    bmapFlag,a0    ;SrcBitMap
  2947.         movea.l    (mgg_Flag,a5),a1    ;DstBitBap
  2948.         jsr    (_LVOBltBitMap,a6)
  2949.         movem.l    (sp),d0/d1    ;restore damaged regs.
  2950.         lea    bmapNoFlag,a0    ;SrcBitMap
  2951.         movea.l    (mgg_NoFlag,a5),a1    ;DstBitBap
  2952.         jsr    (_LVOBltBitMap,a6)
  2953.         movem.l    (sp),d0/d1    ;restore damaged regs.
  2954.         lea    bmapBomb,a0    ;SrcBitMap
  2955.         movea.l    (mgg_Bomb,a5),a1    ;DstBitBap
  2956.         jsr    (_LVOBltBitMap,a6)
  2957.         movem.l    (sp),d0/d1    ;restore damaged regs.
  2958.         lea    bmapBlowed,a0    ;SrcBitMap
  2959.         movea.l    (mgg_Blowed,a5),a1    ;DstBitBap
  2960.         jsr    (_LVOBltBitMap,a6)
  2961.         movem.l    (sp)+,d0/d1    ;restore damaged regs. (+)
  2962.  
  2963. .skipnotscale
  2964.     ;**Now create number buttons
  2965.     ;get fonts baseline and xy-sizes
  2966.  
  2967.         movea.l    a3,a1    ;rp    ;set pens
  2968.         moveq    #1,d0    ;pen
  2969.         jsr    (_LVOSetAPen,a6)
  2970.         movea.l    a3,a1    ;rp
  2971.         moveq    #0,d0
  2972.         jsr    (_LVOSetBPen,a6)
  2973.  
  2974.         movea.l    WinFont,a0
  2975.         move.w    (tf_XSize,a0),d0
  2976.         asr.w    #1,d0
  2977.         move.w    ButtWidth,d2
  2978.         asr.w    #1,d2
  2979.         sub.w    d0,d2        ;xpos
  2980.  
  2981.         move.w    (tf_YSize,a0),d0
  2982.         asr.w    #1,d0
  2983.         move.w    ButtHeight,d3
  2984.         asr.w    #1,d3
  2985.         sub.w    d0,d3
  2986.         add.w    (tf_Baseline,a0),d3    ;ypos
  2987.  
  2988.         movea.l    MGGfx,a5
  2989.         movea.l    _GfxBase,a6
  2990.         moveq    #8-1,d7        ;numbers 1-8
  2991.         moveq    #0,d6        ;offset
  2992.         move.b    #'1',d5        ;char
  2993.  
  2994.         clr.w    Storage
  2995. .loopt        move.l    (mgg_Num1,a5,d6.w),(rp_BitMap,a3)
  2996.         movea.l    a3,a1        ;rp
  2997.         move.w    d2,d0        ;x
  2998.         move.w    d3,d1        ;y
  2999.         ext.l    d0
  3000.         ext.l    d1
  3001.         jsr    (_LVOMove,a6)
  3002.         moveq    #1,d0        ;len
  3003.         movea.l    a3,a1        ;rp
  3004.         lea    Storage,a0    ;string
  3005.         move.b    d5,(a0)        ;put char
  3006.         jsr    (_LVOText,a6)
  3007.         addq.w    #4,d6        ;next bitmap
  3008.         addq.b    #1,d5        ;next number
  3009.         dbra    d7,.loopt
  3010.     ;create questionmark
  3011.         move.w    d2,d4        ;store
  3012.         move.w    d3,d5
  3013.         movea.l    a3,a1        ;rp
  3014.         moveq    #QUESTBACKCOLOR,d0
  3015.         jsr    (_LVOSetAPen,a6)
  3016.         moveq    #2,d0
  3017.         moveq    #1,d1
  3018.         move.w    ButtWidth,d2
  3019.         subq.w    #3,d2
  3020.         ext.l    d2
  3021.         move.w    ButtHeight,d3
  3022.         subq.w    #2,d3
  3023.         ext.l    d3
  3024.         move.l    (mgg_Question,a5),(rp_BitMap,a3)
  3025.         movea.l    a3,a1
  3026.         jsr    (_LVORectFill,a6)    ;fill the background
  3027.  
  3028.         movea.l    a3,a1    ;rp    ;set pens
  3029.         moveq    #1,d0    ;pen
  3030.         jsr    (_LVOSetAPen,a6)
  3031.         movea.l    a3,a1    ;rp
  3032.         moveq    #QUESTBACKCOLOR,d0
  3033.         jsr    (_LVOSetBPen,a6)
  3034.         move.l    (mgg_Question,a5),(rp_BitMap,a3)
  3035.         movea.l    a3,a1    ;rp
  3036.         move.w    d4,d0    ;x
  3037.         move.w    d5,d1    ;y
  3038.         ext.l    d0
  3039.         ext.l    d1
  3040.         jsr    (_LVOMove,a6)
  3041.         moveq    #1,d0    ;len
  3042.         movea.l    a3,a1    ;rp
  3043.         lea    Storage,a0
  3044.         clr.w    (a0)
  3045.         move.b    #'?',(a0) ;string
  3046.         jsr    (_LVOText,a6)
  3047.         rts
  3048.  
  3049. creategfx_error    lea    nomygfx_Text,a1
  3050.         lea    nomygfx_Button,a2
  3051.         bsr.w    InformationReq
  3052.         clr.l    MGGfx
  3053.         rts
  3054. ;*****************************************************************
  3055. FreeGfx        movea.l    _GfxBase,a6
  3056.         jsr    (_LVOWaitBlit,a6)
  3057.         movea.l    MGGfx,a2
  3058.         moveq    #GADBPLNUM-1,d2
  3059. .loop        move.l    (a2)+,d0    ;bitmaps
  3060.         beq.s    .exit
  3061.         movea.l    d0,a0
  3062.         jsr    (_LVOFreeBitMap,a6)
  3063.         dbra    d2,.loop
  3064. .exit        rts
  3065. ;*****************************************************************
  3066. PutButton    ;puts a single button on x,y (d0.w/d1.w)
  3067.         ;d2.w = button number (e.G. mgg_Empty/4)
  3068.  
  3069.         movea.l    MGGfx,a3    ;src bitmaps
  3070.         movea.l    _GfxBase,a6
  3071.  
  3072.     ;check range 1..PFw/h-1
  3073.         cmpi.w    #1,d0
  3074.         blt.w    .exit
  3075.         cmpi.w    #1,d1
  3076.         blt.w    .exit
  3077.         move.w    d0,d4
  3078.         addq.w    #1,d4
  3079.         cmp.w    PFWidth,d4
  3080.         bge.w    .exit
  3081.         move.w    d1,d5
  3082.         addq.w    #1,d5
  3083.         cmp.w    PFHeight,d5
  3084.         bge.w    .exit
  3085.  
  3086.         movea.l    (a3,d2.w*4),a0        ;SrcBitMap
  3087.  
  3088.         move.w    ButtWidth,d4    ;SizeX
  3089.         ext.l    d4
  3090.         move.w    ButtHeight,d5    ;SizeY
  3091.         ext.l    d5
  3092.  
  3093.         move.w    d0,d2
  3094.         move.w    d1,d3
  3095.         subq.w    #1,d2
  3096.         subq.w    #1,d3
  3097.         mulu.w    d4,d2
  3098.         mulu.w    d5,d3
  3099.         add.w    MinPFX,d2    ;DstX
  3100.         ext.l    d2
  3101.         add.w    MinPFY,d3    ;DstY
  3102.         ext.l    d3
  3103.  
  3104.         movea.l    MyWindow,a1
  3105.         movea.l    (wd_RPort,a1),a1    ;DstRPort
  3106.  
  3107.         moveq    #0,d0        ;SrcX
  3108.         move.l    d0,d1        ;SrcY
  3109.         move.l    #$c0,d6        ;Minterm
  3110.  
  3111.         jsr    (_LVOBltBitMapRastPort,a6)
  3112.  
  3113. .exit        rts
  3114. ;*****************************************************************
  3115. ShowButton    ;IN: d0.w = x ,  d1.w = y, d2.w = PF position
  3116.         ;NOTE: x,y,d2.w is a real position in the PF <1.. *-1>
  3117.         ;displays contens of first field at pos. x,y
  3118.         ;and if empty, seedfills whole empty area
  3119.         ;RETURN: d0.b - num. of button pressed (e.G. bomb)
  3120.  
  3121.         movea.l    sp,a2
  3122.         move.l    SeedFillSP,sp
  3123.         move.l    a2,-(sp)
  3124.         bsr.s    .go
  3125.         movea.l    (sp)+,sp
  3126.         rts
  3127.  
  3128. .go        movea.l    MyWindow,a2
  3129.         movea.l    MGGfx,a3    ;src bitmaps
  3130.         movea.l    PFAdr,a4    ;1st field
  3131.         movea.l    a4,a5
  3132.         adda.w    PFSize,a5    ;2nd field
  3133.         movea.l    _GfxBase,a6
  3134.  
  3135.         clr.b    d7
  3136. .seedfill
  3137.     ;check range 1..PFw/h-1
  3138.         cmpi.w    #1,d0
  3139.         blo.w    .exit
  3140.         cmpi.w    #1,d1
  3141.         blo.w    .exit
  3142.         move.w    d0,d4
  3143.         addq.w    #1,d4
  3144.         cmp.w    PFWidth,d4
  3145.         bhs.w    .exit
  3146.         move.w    d1,d5
  3147.         addq.w    #1,d5
  3148.         cmp.w    PFHeight,d5
  3149.         bhs.w    .exit
  3150.  
  3151.         cmpi.b    #QMARK,(a5,d2.w)
  3152.         bne.s    .0
  3153.         tst.b    ([MyPrefs],mprf_DeadQ)
  3154.         beq.w    .exit
  3155.         bra.s    .deadq
  3156.  
  3157. .0        tst.b    (a5,d2.w)    ;pressed or flag?
  3158.         bne.w    .exit        ;yes
  3159.  
  3160. .deadq        move.b    #1,(a5,d2.w)    ;pressed
  3161.         move.b    (a4,d2.w),d7
  3162.         bne.w    .cont
  3163.  
  3164.         movem.w    d0/d1/d2/d7,-(sp)
  3165.         sub.w    PFWidth,d2        ;u
  3166.         subq.w    #1,d1
  3167.         bsr.s    .seedfill
  3168.         movem.w    (sp),d0/d1/d2/d7
  3169.         sub.w    PFWidth,d2
  3170.         subq.w    #1,d2            ;ul
  3171.         subq.w    #1,d0
  3172.         subq.w    #1,d1
  3173.         bsr.s    .seedfill
  3174.         movem.w    (sp),d0/d1/d2/d7
  3175.         sub.w    PFWidth,d2
  3176.         addq.w    #1,d2            ;ur
  3177.         addq.w    #1,d0
  3178.         subq.w    #1,d1
  3179.         bsr.w    .seedfill
  3180.         movem.w    (sp),d0/d1/d2/d7
  3181.         subq.w    #1,d2            ;l
  3182.         subq.w    #1,d0
  3183.         bsr.w    .seedfill
  3184.         movem.w    (sp),d0/d1/d2/d7
  3185.         addq.w    #1,d2            ;r
  3186.         addq.w    #1,d0
  3187.         bsr.w    .seedfill
  3188.         movem.w    (sp),d0/d1/d2/d7
  3189.         add.w    PFWidth,d2        ;d
  3190.         addq.w    #1,d1
  3191.         bsr.w    .seedfill
  3192.         movem.w    (sp),d0/d1/d2/d7
  3193.         add.w    PFWidth,d2
  3194.         subq.w    #1,d2            ;dl
  3195.         addq.w    #1,d1
  3196.         subq.w    #1,d0
  3197.         bsr.w    .seedfill
  3198.         movem.w    (sp),d0/d1/d2/d7
  3199.         add.w    PFWidth,d2
  3200.         addq.w    #1,d2            ;dr
  3201.         addq.w    #1,d1
  3202.         addq.w    #1,d0
  3203.         bsr.w    .seedfill
  3204.         movem.w    (sp)+,d0/d1/d2/d7
  3205.  
  3206. .cont        subq.w    #1,WinCount
  3207.         ext.w    d7
  3208.         movea.l    (a3,d7.w*4),a0        ;SrcBitMap
  3209.  
  3210.         move.w    ButtWidth,d4    ;SizeX
  3211.         ext.l    d4
  3212.         move.w    ButtHeight,d5    ;SizeY
  3213.         ext.l    d5
  3214.  
  3215.         move.w    d0,d2
  3216.         move.w    d1,d3
  3217.         subq.w    #1,d2
  3218.         subq.w    #1,d3
  3219.         mulu.w    d4,d2
  3220.         mulu.w    d5,d3
  3221.         add.w    MinPFX,d2    ;DstX
  3222.         ext.l    d2
  3223.         add.w    MinPFY,d3    ;DstY
  3224.         ext.l    d3
  3225.  
  3226.         movea.l    (wd_RPort,a2),a1    ;DstRPort
  3227.  
  3228.         moveq    #0,d0        ;SrcX
  3229.         move.l    d0,d1        ;SrcY
  3230.         move.l    #$c0,d6        ;Minterm
  3231.  
  3232.         jsr    (_LVOBltBitMapRastPort,a6)
  3233. .exit
  3234.         move.b    d7,d0
  3235.         rts
  3236. ;*****************************************************************
  3237. ClearWin    movea.l    _GfxBase,a6
  3238.  
  3239.         movea.l    MyWindow,a0
  3240.         movea.l    (wd_RPort,a0),a1
  3241.  
  3242.         move.w    MinX,d0
  3243.         ext.l    d0
  3244.         move.w    MinY,d1
  3245.         ext.l    d1
  3246.  
  3247.         move.w    d0,d2
  3248.         add.w    InnWidth,d2
  3249.         subq.w    #1,d2
  3250.         ext.l    d2
  3251.         move.w    d1,d3
  3252.         add.w    InnHeight,d3
  3253.         subq.w    #1,d3
  3254.         ext.l    d3
  3255.         jsr    (_LVOEraseRect,a6)    ;clear
  3256.  
  3257.         rts
  3258. ;*****************************************************************
  3259. RedrawMainBar    bsr.w    RedrawGadget
  3260.     ;**get new Time and BCount display positions
  3261.         move.w    MinX,d0
  3262.         add.w    InnWidth,d0
  3263.         subi.w    #NUMBBOXX+NUMDISTANCE,d0
  3264.         move.w    d0,TimeX
  3265.         move.w    MyBarHeight,d0
  3266.         asr.w    #1,d0        ;/2
  3267.         add.w    MinY,d0
  3268.         subi.w    #NUMBBOXY/2,d0
  3269.         move.w    d0,TimeY
  3270.         move.w    d0,BCountY
  3271.         move.w    MinX,d0
  3272.         addq.w    #NUMDISTANCE,d0
  3273.         move.w    d0,BCountX
  3274.  
  3275.     ;**redraw time and bombs (0)
  3276.         move.w    TimeX,d0
  3277.         move.w    TimeY,d1
  3278.         move.w    MyTime+2,d2
  3279.         bsr.w    DrawNumber
  3280.         move.w    BCountX,d0
  3281.         move.w    BCountY,d1
  3282.         move.w    BCount,d2
  3283.         bsr.w    DrawNumber
  3284.         rts
  3285. ;*****************************************************************
  3286. RedrawWindow    ;IN: d0-type of redrawing (BYTE)
  3287.         tst.b    Disable        ;is window o.k.?
  3288.         bne.w    ClearWin
  3289.  
  3290.         move.w    d0,-(sp)
  3291.         bsr.w    RedrawMainBar
  3292.         move.w    (sp)+,d0
  3293.  
  3294.         tst.b    Pause
  3295.         bne.s    .ret
  3296.  
  3297.         pea    (.ret,pc)
  3298.         cmpi.b    #RW_START,d0
  3299.         beq.s    redrStart
  3300.         cmpi.b    #RW_END,d0
  3301.         beq.w    redrEnd
  3302.         cmpi.b    #RW_ACTUAL,d0
  3303.         beq.w    redrActual
  3304.         addq.w    #4,a7
  3305. .ret
  3306.         rts
  3307. ;------------------------------------------------------------------
  3308. redrStart
  3309.     ;get window position first
  3310.         move.w    MinPFX,d0
  3311.         ext.l    d0
  3312.         move.w    MinPFY,d1
  3313.         ext.l    d1
  3314.         movem.l    d0/d1,-(sp)    ;store x and y
  3315.  
  3316.         moveq    #1,d0
  3317.         move.l    d0,d1
  3318.         moveq    #mgg_Empty/4,d2
  3319.         bsr.w    PutButton    ;put the first button
  3320.  
  3321.         movea.l    _GfxBase,a6
  3322.         movea.l    MyWindow,a0
  3323.         movea.l    (wd_RPort,a0),a3
  3324.         suba.l    a2,a2        ;TempA
  3325.  
  3326.     ;fill the first line (x steps)
  3327.         movea.w    PFWidth,a4    ;required buttons to complete x
  3328.         subq.w    #2,a4
  3329.         movea.w    #2,a5        ;already completed
  3330.  
  3331.         movem.l    (sp),d2/d3    ;destx/desty
  3332.         add.w    ButtWidth,d2    ;destx
  3333.         ext.l    d2
  3334.  
  3335.         move.w    ButtWidth,d4    ;sizex
  3336.         ext.l    d4
  3337.         move.w    ButtHeight,d5    ;sizey
  3338.         ext.l    d5
  3339.         move.l    #$c0,d6    ;miniterm
  3340.  
  3341. .nextx        movem.l    (sp),d0/d1    ;start position
  3342.                 ;(always upper left corner of the window)
  3343.         movea.l    a3,a0        ;source and dest. bmap
  3344.         movea.l    a3,a1
  3345.         jsr    (_LVOClipBlit,a6)
  3346.         add.l    d4,d4        ;sizex*2
  3347.         move.l    d4,d2        ;destx
  3348.         add.l    (sp),d2        ;(+win. offset)
  3349.         adda.w    a5,a5
  3350.         cmpa.w    a5,a4
  3351.         bhs.s    .nextx
  3352.  
  3353.         move.w    a5,d4
  3354.         asr.w    #1,d4
  3355.         move.w    d4,d2
  3356.         ext.l    d4
  3357.         mulu.w    ButtWidth,d2    ;destx
  3358.         add.l    (sp),d2
  3359.         neg.l    d4
  3360.         add.l    a4,d4        ;get the rest of buttons
  3361.         beq.s    .xcomplete
  3362.         mulu.w    ButtWidth,d4    ;sizex
  3363.  
  3364.         movem.l    (sp),d0/d1
  3365.         movea.l    a3,a0
  3366.         movea.l    a3,a1
  3367.         jsr    (_LVOClipBlit,a6)
  3368.  
  3369. .xcomplete    ;**now do similar with y blocks
  3370.         movea.w    PFHeight,a4    ;required lines to complete y
  3371.         subq.w    #2,a4
  3372.         movea.w    #2,a5        ;already completed
  3373.  
  3374.         movem.l    (sp),d2/d3    ;destx/desty
  3375.         add.w    ButtHeight,d3    ;desty
  3376.         ext.l    d3
  3377.         move.w    PFWidth,d4    ;sizex
  3378.         subq.w    #2,d4
  3379.         mulu.w    ButtWidth,d4    ;&
  3380.  
  3381.         move.w    ButtHeight,d5    ;sizey
  3382.         ext.l    d5
  3383.  
  3384. .nexty        movem.l    (sp),d0/d1    ;start position
  3385.                 ;(always upper left corner of the window)
  3386.         movea.l    a3,a0        ;source and dest. bmap
  3387.         movea.l    a3,a1
  3388.         jsr    (_LVOClipBlit,a6)
  3389.         add.l    d5,d5        ;sizey*2
  3390.         move.l    d5,d3        ;desty
  3391.         add.l    (4,sp),d3
  3392.         adda.w    a5,a5
  3393.         cmpa.w    a5,a4
  3394.         bhs.s    .nexty
  3395.  
  3396.         move.w    a5,d5
  3397.         asr.w    #1,d5
  3398.         move.w    d5,d3
  3399.         ext.l    d5
  3400.         mulu.w    ButtHeight,d3    ;desty
  3401.         add.l    (4,sp),d3
  3402.         neg.l    d5
  3403.         add.l    a4,d5        ;get the rest of lines
  3404.         beq.s    .ycomplete
  3405.         mulu.w    ButtHeight,d5    ;sizey
  3406.  
  3407.         movem.l    (sp),d0/d1
  3408.         movea.l    a3,a0
  3409.         movea.l    a3,a1
  3410.         jsr    (_LVOClipBlit,a6)
  3411. .ycomplete
  3412.         addq.l    #8,sp        ;restore stack
  3413.         rts
  3414. ;----------------------------------------------------------------
  3415. redrEnd    ;**draw contens of the PlayField
  3416.         move.w    MinPFX,d2    ;DstX
  3417.         ext.l    d2
  3418.         move.w    MinPFY,d3    ;DstY
  3419.         ext.l    d3
  3420.         move.w    ButtWidth,d4    ;SizeX
  3421.         ext.l    d4
  3422.         move.w    ButtHeight,d5    ;SizeY
  3423.         ext.l    d5
  3424.  
  3425.         movea.l    MGGfx,a3    ;src bitmaps
  3426.         movea.l    MyWindow,a4
  3427.         movea.l    (wd_RPort,a4),a4        ;dst
  3428.         movea.l    PFAdr,a5    ;PF contens
  3429.         adda.w    PFWidth,a5    ;pos 1,1
  3430.         addq.w    #1,a5        ;&
  3431.  
  3432.         movea.l    _GfxBase,a6
  3433.         move.w    PFHeight,d7
  3434.         subq.w    #2+1,d7
  3435. .heightloop    move.w    PFWidth,d6
  3436.         subq.w    #2+1,d6
  3437. .widthloop
  3438.         movem.w    d6/d7,-(sp)
  3439.     ;copy bitmap
  3440.         move.w    PFSize,d7
  3441.         move.b    (a5,d7.w),d7
  3442.         move.b    (a5)+,d6
  3443.         cmpi.b    #mgg_Blowed/4,d6
  3444.         beq.s    .next
  3445.         cmpi.b    #mgg_Bomb/4,d6
  3446.         bne.s    .flag
  3447.         cmpi.b    #FLAG,d7
  3448.         beq.s    .next
  3449.         tst.b    Win
  3450.         beq.s    .flok
  3451.         move.b    #mgg_Flag/4,d6
  3452.         bra.s    .flok
  3453.  
  3454. .flag        cmpi.b    #FLAG,d7
  3455.         bne.s    .next
  3456.         move.b    #mgg_NoFlag/4,d6
  3457. .flok
  3458.         ext.w    d6
  3459.         movea.l    (a3,d6.w*4),a0        ;SrcBitMap
  3460.         moveq    #0,d0        ;SrcX
  3461.         move.l    d0,d1        ;SrcY
  3462.         movea.l    a4,a1        ;DstRPort
  3463.         move.l    #$c0,d6        ;Minterm
  3464.  
  3465.         jsr    (_LVOBltBitMapRastPort,a6)
  3466.  
  3467. .next        add.l    d4,d2
  3468.         movem.w    (sp)+,d6/d7
  3469.         dbra    d6,.widthloop
  3470.         add.l    d5,d3
  3471.         addq.w    #2,a5
  3472.         move.w    MinPFX,d2
  3473.         ext.l    d2
  3474.         dbra    d7,.heightloop
  3475.  
  3476.         rts
  3477. ;---------------------------------------------------------------
  3478. redrActual
  3479.         move.w    MinPFX,d2    ;DstX
  3480.         ext.l    d2
  3481.         move.w    MinPFY,d3    ;DstY
  3482.         ext.l    d3
  3483.         move.w    ButtWidth,d4    ;SizeX
  3484.         ext.l    d4
  3485.         move.w    ButtHeight,d5    ;SizeY
  3486.         ext.l    d5
  3487.  
  3488.         movea.l    MGGfx,a3    ;src bitmaps
  3489.         movea.l    MyWindow,a4
  3490.         movea.l    (wd_RPort,a4),a4        ;dst
  3491.         movea.l    PFAdr,a5    ;PF contens
  3492.         movea.l    a5,a2
  3493.         adda.w    PFSize,a2
  3494.         adda.w    PFWidth,a5    ;pos 1,1
  3495.         addq.w    #1,a5        ;&
  3496.         adda.w    PFWidth,a2    ;pos 1,1
  3497.         addq.w    #1,a2        ;&
  3498.  
  3499.  
  3500.         movea.l    _GfxBase,a6
  3501.         move.w    PFHeight,d7
  3502.         subq.w    #2+1,d7
  3503. .heightloop    move.w    PFWidth,d6
  3504.         subq.w    #2+1,d6
  3505. .widthloop
  3506.         move.w    d6,-(sp)
  3507.     ;copy bitmap
  3508.         cmpi.b    #FLAG,(a2)
  3509.         bne.s    .noflag
  3510.         movea.l    (mgg_Flag,a3),a0
  3511.         bra.s    .draw
  3512. .noflag        cmpi.b    #QMARK,(a2)
  3513.         bne.s    .noqmark
  3514.         movea.l    (mgg_Question,a3),a0
  3515.         bra.s    .draw
  3516. .noqmark    tst.b    (a2)    ;pressed?
  3517.         bne.s    .yes    ;yes
  3518.         movea.l    (mgg_Empty,a3),a0
  3519.         bra.s    .draw
  3520. .yes        move.b    (a5),d6
  3521.         ext.w    d6
  3522.         movea.l    (a3,d6.w*4),a0        ;SrcBitMap
  3523. .draw        addq.w    #1,a2
  3524.         addq.w    #1,a5
  3525.         moveq    #0,d0        ;SrcX
  3526.         move.l    d0,d1        ;SrcY
  3527.         movea.l    a4,a1        ;DstRPort
  3528.         move.l    #$c0,d6        ;Minterm
  3529.  
  3530.         jsr    (_LVOBltBitMapRastPort,a6)
  3531.  
  3532.         add.l    d4,d2
  3533.         move.w    (sp)+,d6
  3534.         dbra    d6,.widthloop
  3535.         add.l    d5,d3
  3536.         addq.w    #2,a5
  3537.         addq.w    #2,a2
  3538.         move.w    MinPFX,d2
  3539.         ext.l    d2
  3540.         dbra    d7,.heightloop
  3541.  
  3542.         rts
  3543. ;*****************************************************************
  3544. ResizeWindow    ;**change box
  3545.         bsr.w    SetWinParams
  3546.  
  3547.         bsr.w    RemSunG
  3548.         lea    SunGadget,a0
  3549.         move.l    #0,(gg_GadgetRender,a0)
  3550.         move.l    #0,(gg_SelectRender,a0)
  3551.         bsr.w    AddSunG
  3552.  
  3553.         bsr.w    ClearWin
  3554.     ;**Change the window box
  3555.         movea.l    IntuiBase,a6
  3556.         movea.l    MyWindow,a0
  3557.         move.w    WinX,d0
  3558.         ext.l    d0
  3559.         move.w    WinY,d1
  3560.         ext.l    d1
  3561.         move.w    WinWidth,d2
  3562.         ext.l    d2
  3563.         move.w    WinHeight,d3
  3564.         ext.l    d3
  3565.         jsr    (_LVOChangeWindowBox,a6)
  3566.         st    IDidTheChange
  3567. rw_exit        rts
  3568. ;*****************************************************************
  3569. RedrawGadget    bsr.s    RemSunG
  3570.         movea.l    IntuiBase,a6
  3571.         movea.l    MyWindow,a0
  3572.         jsr    (_LVORefreshWindowFrame,a6)
  3573.         ; no rts !!
  3574. AddGadget
  3575.     ;IN:Gadget_Image.l    gadget image
  3576.         lea    SunGadget,a0    ;set new position of the gadget
  3577.         move.w    InnWidth,d0
  3578.         subi.w    #SUNMINX,d0
  3579.         asr.w    #1,d0
  3580.         add.w    MinX,d0
  3581.         move.w    d0,(gg_LeftEdge,a0)
  3582.         move.w    MyBarHeight,d0
  3583.         subi.w    #SUNMINY,d0
  3584.         asr.w    #1,d0
  3585.         add.w    MinY,d0
  3586.         move.w    d0,(gg_TopEdge,a0)
  3587.  
  3588.     ;set appropriate gadget image
  3589.         tst.b    Disable
  3590.         beq.s    .norm
  3591.         clr.l    (gg_GadgetRender,a0)
  3592.         clr.l    (gg_SelectRender,a0)
  3593.         bra.s    .dis
  3594. .norm        move.l    Gadget_Image,(gg_GadgetRender,a0)
  3595.         move.l    #img_SunPressed,(gg_SelectRender,a0)
  3596. .dis        bsr.s    AddSunG
  3597.  
  3598.         movea.l    IntuiBase,a6
  3599.         lea    SunGadget,a0
  3600.         movea.l    MyWindow,a1
  3601.         suba.l    a2,a2
  3602.         jsr    (_LVORefreshGadgets,a6)
  3603.         rts
  3604. ;---------------------------
  3605. RemSunG        movea.l    IntuiBase,a6
  3606.         movea.l    MyWindow,a0
  3607.         lea    SunGadget,a1
  3608.         jsr    (_LVORemoveGadget,a6)    ;I'm not able to handle errors
  3609.         rts
  3610. AddSunG        movea.l    IntuiBase,a6
  3611.         moveq    #0,d0
  3612.         movea.l    MyWindow,a0
  3613.         lea    SunGadget,a1
  3614.         jsr    (_LVOAddGadget,a6)
  3615.         rts
  3616. ;*****************************************************************
  3617. ChangeIDCMP    ;IN: d0 - idcmp flags
  3618.         movea.l    IntuiBase,a6
  3619.         movea.l    MyWindow,a0
  3620.         move.l    OldIDCMP,d2
  3621.         eor.l    d2,d0
  3622.         move.l    d0,d2
  3623.         jsr    (_LVOModifyIDCMP,a6)
  3624.         tst.l    d0
  3625.         beq.s    .fail
  3626.         move.l    d2,OldIDCMP
  3627. .fail        rts
  3628. ;*****************************************************************
  3629. OpenMyWindow
  3630.     ;**Open MyWindow
  3631.         movea.l    IntuiBase,a6
  3632.         suba.l    a0,a0    ;NewWindow=0
  3633.         lea    MyWinTags,a1    ;TagList
  3634.         jsr    (_LVOOpenWindowTagList,a6)
  3635.         move.l    d0,MyWindow
  3636.         bne.s    .cont
  3637.         lea    nowin_Text,a1
  3638.         lea    nowin_Button,a2
  3639.         bsr.w    InformationReq
  3640.         bra.s    .nowindow
  3641. .cont
  3642.     ;*set new window pointer for ReqTools requesters
  3643.         move.l    MyWindow,d0
  3644.         move.l    d0,IReqTags+12
  3645.         move.l    d0,JoinGetTags+4
  3646.         move.l    d0,GSReqTags+4
  3647.         move.l    d0,HiScoresTags+4
  3648.     ;**set font
  3649.         move.l    WinFont,d0
  3650.         beq.s    .skip
  3651.         movea.l    _GfxBase,a6
  3652.         movea.l    d0,a0        ;font
  3653.         movea.l    MyWindow,a1
  3654.         movea.l    (wd_RPort,a1),a1        ;rp
  3655.         jsr    (_LVOSetFont,a6)
  3656. .skip
  3657. .nowindow    rts
  3658. ;----------------------------------------------------------
  3659. CloseMyWindow    movea.l    (EB,PC),a6
  3660.         movea.l    Semaphore,a0
  3661.         jsr    (_LVOObtainSemaphore,a6)
  3662.     ;**collect all possible pending messages
  3663.         movea.l    MyWindow,a2
  3664.         move.l    (wd_UserPort,a2),d2
  3665.         beq.s    .noport
  3666. .cl        movea.l    d2,a0
  3667.         jsr    (_LVOGetMsg,a6)
  3668.         tst.l    d0
  3669.         bne.s    .cl
  3670.  
  3671.         moveq    #0,d0
  3672.         clr.l    OldIDCMP
  3673.         bsr.w    ChangeIDCMP    ;close IDCMP ports
  3674. .noport
  3675.         movea.l    (EB,PC),a6
  3676.         movea.l    Semaphore,a0
  3677.         jsr    (_LVOReleaseSemaphore,a6)
  3678.  
  3679.         movea.l    IntuiBase,a6
  3680.         movea.l    MyWindow,a0
  3681.         jsr    (_LVOCloseWindow,a6)
  3682.  
  3683.     ;*set zero pointer for ReqTools requesters
  3684.         moveq    #0,d0
  3685.         move.l    d0,IReqTags+12
  3686.         move.l    d0,JoinGetTags+4
  3687.         move.l    d0,GSReqTags+4
  3688.         move.l    d0,HiScoresTags+4
  3689.         rts
  3690. ;**********************************************************************
  3691. OpenMyScreen
  3692.     ;**Check settings
  3693.         movea.l    MyPrefs,a0
  3694.         tst.b    (mprf_CustomScreen,a0)    ;customscreen=yes?
  3695.         beq.w    noscreen
  3696.  
  3697.     ;set tags
  3698.         lea    MyScreenTags,a1
  3699. tagloop        move.l    (a1)+,d0
  3700.         cmpi.l    #TAG_DONE,d0
  3701.         beq.w    tags_done
  3702.         cmpi.l    #SA_Width,d0
  3703.         beq.s    .setWidth
  3704.         cmpi.l    #SA_Height,d0
  3705.         beq.s    .setHeight
  3706.         cmpi.l    #SA_DisplayID,d0
  3707.         beq.s    .setModeID
  3708.         cmpi.l    #SA_LikeWorkbench,d0
  3709.         beq.s    .wblike
  3710.  
  3711.         addq.w    #4,a1        ;just other tag
  3712.         bra.s    tagloop
  3713. .setWidth    move.w    (mprf_ScrWidth,a0),d0
  3714.         ext.l    d0
  3715.         bne.s    .0
  3716.         move.l    #STDSCREENWIDTH,d0
  3717. .0        move.l    d0,(a1)+
  3718.         bra.s    tagloop
  3719. .setHeight    move.w    (mprf_ScrHeight,a0),d0
  3720.         ext.l    d0
  3721.         bne.s    .1
  3722.         move.l    #STDSCREENHEIGHT,d0
  3723. .1        move.l    d0,(a1)+
  3724.         bra.s    tagloop
  3725. .setModeID    move.l    (mprf_ModeID,a0),d0
  3726.         bne.s    .2
  3727.         move.l    #PAL_MONITOR_ID!HIRES_KEY,d0
  3728.         move.l    d0,(mprf_ModeID,a0)
  3729. .2        move.l    d0,(a1)+
  3730.         bra.w    tagloop
  3731. .wblike        tst.b    (mprf_WBLike,a0)
  3732.         bne.s    .wbl
  3733.         move.l    #FALSE,(a1)+
  3734.         bra.s    tagloop
  3735. .wbl        move.l    #TRUE,(a1)+
  3736.         move.l    #TAG_DONE,(a1)
  3737. tags_done
  3738.     ;**Open screen
  3739.         movea.l    IntuiBase,a6
  3740.         suba.l    a0,a0    ;NewScreen
  3741.         lea    MyScreenTags,a1
  3742.         jsr    (_LVOOpenScreenTagList,a6)
  3743.  
  3744.         move.l    d0,MyScreen
  3745.         bne.s    .ok
  3746.         lea    NoScr_Text,a1
  3747.         lea    NoScr_Button,a2
  3748.         bsr.w    InformationReq
  3749.         clr.b    ([MyPrefs],mprf_CustomScreen)
  3750. .ok
  3751. noscreen    rts
  3752.  
  3753. ;*******
  3754. CloseMyScreen    movea.l    IntuiBase,a6
  3755.         movea.l    MyScreen,a0
  3756.         movea.l    MyDrawInfo,a1
  3757.         jsr    (_LVOFreeScreenDrawInfo,a6)
  3758.  
  3759.         tst.b    ([MyPrefs],mprf_CustomScreen)
  3760.         bne.s    .cust
  3761.         suba.l    a0,a0
  3762.         movea.l    MyScreen,a1
  3763.         jsr    (_LVOUnlockPubScreen,a6)
  3764.         bra.s    .exit
  3765. .cust
  3766.         movea.l    MyScreen,a0
  3767.         jsr    (_LVOCloseScreen,a6)
  3768. .exit        rts
  3769. ;*****************************************************************
  3770. SetPalette
  3771.         tst.b    ([MyPrefs],mprf_CustomScreen)
  3772.         beq.s    .exit
  3773.         movea.l    MyScreen,a0
  3774.     ;**Set palette here
  3775.         movea.l    _GfxBase,a6
  3776.         lea    (sc_ViewPort,a0),a0
  3777.         lea    ScreenPalette,a1    ;palette
  3778.         jsr    (_LVOLoadRGB32,a6)    ;load 8-bit palette
  3779. .exit        rts
  3780. ;*****************************************************************
  3781. OpenFont    movea.l    MyPrefs,a2
  3782.         lea    MyTextAttr,a3
  3783.         move.l    (mprf_FontName,a2),(ta_Name,a3)    ;font name
  3784.         beq.s    .setdefault
  3785.         move.w    (mprf_FontSize,a2),(ta_YSize,a3)    ;font size
  3786.         bne.s    .sizeok    ;if Size=0 then set other size
  3787.     ;**use the designed font
  3788.         move.b    #FPF_DESIGNED,(ta_Flags,a3)
  3789. .sizeok
  3790.     ;**try diskfont
  3791.         movea.l    (EB,PC),a6
  3792.         moveq    #0,d0
  3793.         lea    DiskFontName,a1
  3794.         jsr    (_LVOOpenLibrary,a6)
  3795.         move.l    d0,Storage
  3796.         beq.s    .rom
  3797.  
  3798.         movea.l    d0,a6    ;library base
  3799.         movea.l    a3,a0    ;TTextAttr
  3800.         jsr    (_LVOOpenDiskFont,a6)
  3801.         move.l    d0,WinFont
  3802.  
  3803.         movea.l    (EB,PC),a6
  3804.         movea.l    Storage,a1    ;diskfont.library base
  3805.         jsr    (_LVOCloseLibrary,a6)
  3806.  
  3807.         tst.l    WinFont
  3808.         bne.s    .exit
  3809.  
  3810. .rom        movea.l    _GfxBase,a6
  3811.         movea.l    a3,a0        ;TextAttr
  3812.         jsr    (_LVOOpenFont,a6)
  3813.         move.l    d0,WinFont
  3814.         bne.s    .exit
  3815.  
  3816.         lea    nofont_Text,a1
  3817.         lea    nofont_Button,a2
  3818.         bsr.w    InformationReq
  3819. .setdefault    movea.l    _GfxBase,a0
  3820.         move.l    (gb_DefaultFont,a0),WinFont
  3821.         clr.l    ([MyPrefs],mprf_FontName)
  3822.         rts
  3823. .exit
  3824.         move.l    ([WinFont],LN_NAME),([MyPrefs],mprf_FontName)
  3825.         rts
  3826.  
  3827. CloseFont    move.l    WinFont,d0
  3828.         beq.s    .exit
  3829.         movea.l    _GfxBase,a6
  3830.         movea.l    d0,a1
  3831.         jsr    (_LVOCloseFont,a6)
  3832. .exit        rts
  3833. ;*****************************************************************
  3834. FontToRT    movea.l    _GfxBase,a6
  3835.         movea.l    (gb_DefaultFont,a6),a0
  3836.         lea    MyTextAttr,a1
  3837.         move.l    (LN_NAME,a0),(a1)    ;LN_NAME -> ta_Name
  3838.         move.w    (tf_YSize,a0),(ta_YSize,a1)
  3839.         move.b    (tf_Style,a0),(ta_Style,a1)
  3840.         move.b    (tf_Flags,a0),(ta_Flags,a1)
  3841.         rts
  3842. ;*****************************************************************
  3843. GetDRI    ;**get screen draw info
  3844.         movea.l    IntuiBase,a6
  3845.         movea.l    MyScreen,a0
  3846.         jsr    (_LVOGetScreenDrawInfo,a6)
  3847.         move.l    d0,MyDrawInfo
  3848.         rts
  3849. ;*****************************************************************
  3850. LockScreen    movea.l    IntuiBase,a6
  3851.         tst.l    MyScreen
  3852.         bne.s    nolock
  3853.  
  3854.         move.l    ([MyPrefs],mprf_PubNameAdr),d0    ;any public screen specified?
  3855.         beq.s    .wb            ;no
  3856.         movea.l    d0,a0            ;$ check if it's open
  3857.         jsr    (_LVOLockPubScreen,a6)
  3858.         tst.l    d0
  3859.         bne.s    .gotone            ;$ yes it is
  3860.         clr.l    ([MyPrefs],mprf_PubNameAdr)
  3861.  
  3862. .wb        suba.l    a0,a0    ;Workbench or default public screen
  3863.         jsr    (_LVOLockPubScreen,a6)
  3864. .gotone        move.l    d0,MyScreen
  3865. nolock        rts
  3866.  
  3867. ;*****************************************************************
  3868. SetMenu
  3869.     ;Create NewMenu structure for gadtools.library
  3870.         lea    MyMenu,a0
  3871.         lea    GTNewMenu,a1
  3872.  
  3873. .copy        move.b    (mmi_Type,a0),d0
  3874.         beq.w    .copied
  3875.         move.b    d0,(gnm_Type,a1)
  3876.         move.w    (mmi_Flags,a0),(gnm_Flags,a1)
  3877.         move.l    (mmi_CommKey,a0),(gnm_CommKey,a1)
  3878.         move.l    (mmi_Mutual,a0),(gnm_MutualExclude,a1)
  3879.         move.l    (mmi_Name,a0),(gnm_Label,a1)
  3880.  
  3881.         lea    (mmi_SIZEOF,a0),a0
  3882.         lea    (gnm_SIZEOF,a1),a1
  3883.         bra.s    .copy
  3884. .copied
  3885.         movea.l    GadtoolsBase,a6
  3886.         lea    GTNewMenu,a0
  3887.         lea    NewMenuTags,a1
  3888.         jsr    (_LVOCreateMenusA,a6)
  3889.         move.l    d0,MenuStruct
  3890.         beq.s    NoMenu
  3891.  
  3892.         movea.l    MenuStruct,a0
  3893.         movea.l    VisualInfo,a1
  3894.         lea    LayoutTags,a2
  3895.         jsr    (_LVOLayoutMenusA,a6)
  3896.         tst.l    d0
  3897.         beq.s    NoMenu2
  3898.  
  3899.     ;Hey! set it finally!
  3900.         movea.l    IntuiBase,a6
  3901.         movea.l    MyWindow,a0
  3902.         movea.l    MenuStruct,a1
  3903.         jsr    (_LVOSetMenuStrip,a6)
  3904.  
  3905.     ;set checkmark due to level
  3906.         move.b    ([MyPrefs],mprf_Level),d0
  3907.         subq.b    #1,d0
  3908.         ext.w    d0
  3909.         mulu.w    #mmi_SIZEOF,d0
  3910.         lea    LevelItems,a0
  3911.         move.w    (mmi_Code,a0,d0.w),d0
  3912.  
  3913.         ext.l    d0    ;to be sure
  3914.         movea.l    IntuiBase,a6
  3915.         movea.l    MenuStruct,a0
  3916.         jsr    (_LVOItemAddress,a6)
  3917.         movea.l    d0,a0
  3918.         ori.w    #CHECKED,(mi_Flags,a0)    ;set checkmark
  3919.         rts
  3920.  
  3921. NoMenu2        movea.l    MenuStruct,a0
  3922.         jsr    (_LVOFreeMenus,a6)
  3923. NoMenu        clr.l    MenuStruct
  3924.         lea    nomenu_Text,a1
  3925.         lea    nomenu_Button,a2
  3926.         bsr.w    InformationReq
  3927.         rts
  3928. ;-------------------------------------------------------
  3929. ClearMenu    tst.l    MenuStruct
  3930.         beq.s    .nomenu
  3931.         movea.l    IntuiBase,a6
  3932.         movea.l    MyWindow,a0
  3933.         jsr    (_LVOClearMenuStrip,a6)
  3934.  
  3935.         movea.l    GadtoolsBase,a6
  3936.         movea.l    MenuStruct,a0
  3937.         jsr    (_LVOFreeMenus,a6)
  3938. .nomenu        rts
  3939. ;*****************************************************************
  3940. InformationReq    ;IN: a1 - text  a2 - button text
  3941.         movem.l    d1-d7/a0-a6,-(sp)
  3942.         movea.l    _ReqToolsBase,a6
  3943.         suba.l    a3,a3
  3944.         suba.l    a4,a4
  3945.         lea    IReqTags,a0
  3946.         jsr    (_LVOrtEZRequestA,a6)
  3947.         movem.l    (sp)+,d1-d7/a0-a6
  3948.         rts
  3949. ;*****************************************************************
  3950. CDProggy    movea.l    DosBase,a6
  3951.         move.l    ProgDir,d1
  3952.         jsr    (_LVOCurrentDir,a6)
  3953.         lea    (olddir,pc),a0
  3954.         move.l    d0,(a0)
  3955.         rts
  3956. CDBack        movea.l    DosBase,a6
  3957.         move.l    (olddir,pc),d1
  3958.         jsr    (_LVOCurrentDir,a6)
  3959.         rts
  3960. olddir        dc.l    0
  3961.  
  3962. ;*****************************************************************
  3963.  
  3964. ;---------------------------------------------------
  3965. HEADSIZE    = 25
  3966. LINESIZE    = 12+NAMELEN+9
  3967. LEVELSIZE    = LINESIZE*2
  3968. CUSTOMSIZE    = LEVELSIZE+6*28
  3969. HS_TEXTMEM    = HEADSIZE+LEVELSIZE*4+LINESIZE+CUSTOMSIZE+1
  3970.  
  3971. MakeHighScores    ;IN: nothing
  3972.         ;Makes a text string for ReqTools
  3973.  
  3974.         movea.l    MyPrefs,a5
  3975.         lea    HiScoresText,a0
  3976.         move.w    #HS_TEXTMEM-2,d7
  3977.         lea    (hs_ScoresText,pc),a1
  3978.         lea    (hs_DataTable,pc),a3
  3979. cploop        move.b    (a1)+,d0
  3980.         cmpi.b    #'$',d0
  3981.         beq.s    .writename
  3982.         cmpi.b    #'%',d0
  3983.         beq.s    .writenumber
  3984.         move.b    d0,(a0)+
  3985.         dbeq    d7,cploop
  3986.         bra.s    hs_AllDone
  3987.  
  3988. .writename    move.b    (a1)+,d0    ;get offset in table
  3989.         ext.w    d0
  3990.         move.w    (a3,d0.w*2),d0    ;get real offset
  3991.         movea.l    a5,a4        ;MyPrefs
  3992.         moveq    #0,d1        ;pocet pismen
  3993. .wnloop0    move.b    (a4,d0.w),(a0)+
  3994.         beq.s    .wndone0
  3995.         addq.l    #1,a4
  3996.         addq.w    #1,d1
  3997.         subq.w    #1,d7
  3998.         bmi.s    hs_AllDone
  3999.         bra.s    .wnloop0
  4000. .wndone0    subq.l    #1,a0
  4001.         move.w    #NAMELEN+4,d2
  4002.         sub.w    d1,d2
  4003.         subq.w    #1,d2
  4004. .wnloop1    move.b    #'.',(a0)+
  4005.         subq.w    #1,d7
  4006.         bmi.s    hs_AllDone
  4007.         dbra    d2,.wnloop1
  4008.         bra.s    cploop
  4009.  
  4010. .writenumber    move.b    (a1)+,d0
  4011.         ext.w    d0
  4012.         move.w    (a3,d0.w*2),d0
  4013.         move.w    (a5,d0.w),d2    ;time from hiscores
  4014.         bsr.w    Num2String4
  4015.         moveq    #4-1,d2
  4016. .nloop        move.b    (a2)+,(a0)+
  4017.         subq.w    #1,d7
  4018.         bmi.s    hs_AllDone
  4019.         dbra    d2,.nloop
  4020.         bra.s    cploop
  4021.  
  4022. hs_AllDone    clr.b    (a0)+
  4023.         rts
  4024.  
  4025. hs_DataTable    dc.w    mhs_EasyName1,mhs_EasyTime1,mhs_EasyName2,mhs_EasyTime2
  4026.         dc.w    mhs_NormalName1,mhs_NormalTime1,mhs_NormalName2,mhs_NormalTime2
  4027.         dc.w    mhs_HardName1,mhs_HardTime1,mhs_HardName2,mhs_HardTime2
  4028.         dc.w    mhs_ProfiName1,mhs_ProfiTime1,mhs_ProfiName2,mhs_ProfiTime2
  4029.         dc.w    mhs_CustomName1,mhs_CustomTime1,mhs_CustomWidth1,mhs_CustomHeight1,mhs_CustomBombs1
  4030.         dc.w    mhs_CustomName2,mhs_CustomTime2,mhs_CustomWidth2,mhs_CustomHeight2,mhs_CustomBombs2
  4031.  
  4032. hs_ScoresText    dc.b    '**** Best sweepers ****',10
  4033.         dc.b    'Easy :   1. $',0,'%',1,10
  4034.         dc.b    '         2. $',2,'%',3,10
  4035.         dc.b    'Medium : 1. $',4,'%',5,10
  4036.         dc.b    '         2. $',6,'%',7,10
  4037.         dc.b    'Hard :   1. $',8,'%',9,10
  4038.         dc.b    '         2. $',10,'%',11,10
  4039.         dc.b    'Profi :  1. $',12,'%',13,10
  4040.         dc.b    '         2. $',14,'%',15,10
  4041.         dcb.b    LINESIZE-1,'-'
  4042.         dc.b    10
  4043.         dc.b    'Custom : 1. $',16,'%',17,10
  4044.         dc.b    '               Width : %',18,10
  4045.         dc.b    '               Height: %',19,10
  4046.         dc.b    '               Mines : %',20,10
  4047.         dc.b    '         2. $',21,'%',22,10
  4048.         dc.b    '               Width : %',23,10
  4049.         dc.b    '               Height: %',24,10
  4050.         dc.b    '               Mines : %',25
  4051.         dc.b    0
  4052.  
  4053.  
  4054.         cnop    0,4
  4055. ;*****************************************************************
  4056. ClearHighScores    ;IN: a0-MyPrefs
  4057.         ; MinesHiScores structure
  4058.         ;   will be filled with defaults (Nobody 9999)
  4059.  
  4060.         st    (mhs_Valid,a0)
  4061.         st    (mhs_NewHiscore,a0)
  4062.     ;**set best times to default
  4063.         lea    (mhs_BestTimes,a0),a1
  4064.         move.w    #(mhs_BTEnd-mhs_BestTimes)/2-1,d0
  4065. .time        move.w    #MAXTIME,(a1)+
  4066.         dbra    d0,.time
  4067.  
  4068.     ;**clear all names
  4069.         lea    (mhs_BestNames,a0),a1
  4070.         move.w    #(mhs_BNEnd-mhs_BestNames)/NAMELEN-1,d0
  4071. .cp0        clr.b    (a1)
  4072.         lea    (NAMELEN,a1),a1
  4073.         dbra    d0,.cp0        ;next
  4074.  
  4075.         clr.l    (mhs_CustomWidth1,a0)    ;1.w,2.w
  4076.         clr.l    (mhs_CustomHeight1,a0)
  4077.         clr.l    (mhs_CustomBombs1,a0)
  4078.         rts
  4079.  
  4080. ;*****************************************************************
  4081. DSIZEW    =    (mhs_SIZEOF-mhs_Data)/2
  4082.  
  4083. GETC        MACRO    ;CHAR,ADD
  4084.         cmpi.b    #\1,d0
  4085.         bne.s    .0\@
  4086.         move.b    (a0)+,d0
  4087.         subq.w    #1,d1
  4088.         addi.b    #\2,d0
  4089.         bra.s    .ok
  4090. .0\@
  4091.         ENDM
  4092.  
  4093. GetMHS        ;decode file and extract MinesHiScores structure
  4094.  
  4095.         ;IN: d1 = (FileLenght - 1) , a5 = filebuffer
  4096.         ;    a4 = MyPrefs
  4097.     ;convert text->zmatky
  4098.         movea.l    a5,a0        ;src
  4099.         movea.l    a5,a1        ;dest
  4100.         moveq    #0,d2        ;lenght
  4101.  
  4102.     ;kill LF
  4103.         move.w    d1,d3
  4104. .lfloop        move.b    (a0)+,d0
  4105.         cmpi.b    #10,d0
  4106.         bne.s    .nolf
  4107.         subq.w    #1,d1
  4108.         bra.s    .lfok
  4109. .nolf        move.b    d0,(a1)+
  4110. .lfok        dbra    d3,.lfloop
  4111.  
  4112.         tst.w    d1
  4113.         bmi.s    .empty
  4114.         movea.l    a5,a0        ;src
  4115.         movea.l    a5,a1        ;dest
  4116. .loop        move.b    (a0)+,d0
  4117.         subq.w    #1,d1
  4118.         bmi.s    .ok
  4119.  
  4120.         GETC    LOWC,-32
  4121.         GETC    MEDC,127-32
  4122.         GETC    HIGHC,222-32
  4123.         move.l    d0,d0
  4124. .ok        move.b    d0,(a1)+
  4125.         addq.w    #1,d2
  4126.         tst.w    d1
  4127.         bpl.s    .loop
  4128. .empty
  4129.         cmpi.l    #hsf_SIZEOF,d2    ;lenght ok?
  4130.         bne.s    .error
  4131.  
  4132.         movea.l    a5,a0        ;file addr
  4133.     ;check coded checksum
  4134.         move.w    #DSIZEW-1,d3
  4135.         moveq    #0,d0
  4136.         lea    (hsf_Data,a0),a0
  4137. .chck        add.w    (a0)+,d0
  4138.         dbra    d3,.chck
  4139.         cmp.w    (hsf_CodedChecksum,a5),d0
  4140.         bne.s    .error
  4141.     ;encode
  4142.         move.l    (a5),d2    ;RndSeed
  4143.         lea    (hsf_Data,a5),a0
  4144.         move.w    #DSIZEW*2,d1
  4145.         bsr.w    Decrypt    ;IN: a0-data, d1-length, d2-RndSeed
  4146.     ;check encoded checksum
  4147.         move.w    #DSIZEW-1,d3
  4148.         moveq    #0,d0
  4149.         lea    (hsf_Data,a5),a0
  4150. .chck2        add.w    (a0)+,d0
  4151.         dbra    d3,.chck2
  4152.         cmp.w    (hsf_DecodedChecksum,a5),d0
  4153.         bne.s    .error
  4154.     ;O.K. the file seems to be correct so fill it to MinesHiScores struct.
  4155.         move.w    #DSIZEW-1,d3
  4156.         lea    (hsf_Data,a5),a0
  4157.         movea.l    a4,a1        ;MyPrefs
  4158.         st    (mhs_Valid,a1)    ;hi-scores are valid
  4159.         lea    (mhs_Data,a1),a1
  4160. .cp        move.w    (a0)+,(a1)+
  4161.         dbra    d3,.cp
  4162.         moveq    #0,d0
  4163.         rts
  4164. .error        moveq    #-1,d0
  4165.         rts
  4166. ;-----------------------------------------------------------
  4167. LoadHiScores
  4168.         bsr.w    CDProggy    ;change directory to program
  4169.         move.l    #HsFileName,d0
  4170.         bsr.w    LOAD_FILE    ;IN:d0-filename  ;OUT: d0-adr. or 0 ;d1- len
  4171.         tst.l    d0        ;store
  4172.         beq.s    .skip
  4173.         lea    (fb,pc),a0    ;store buffer
  4174.         move.l    d0,(a0)
  4175.  
  4176.         bfclr    d1{0:16}
  4177.         bne.s    .empty    ;well, too big
  4178.         subq.w    #1,d1        ;file lenght
  4179.         bmi.s    .empty        ;empty file
  4180.         movea.l    d0,a5
  4181.         movea.l    MyPrefs,a4
  4182.  
  4183.         bsr.w    GetMHS
  4184.  
  4185.         tst.b    d0        ;error?
  4186.         bne.s    .hsc_CrapFile
  4187.  
  4188.         move.w    (hsf_LastXmasYear,a5),LastXmas    ;get last xmas
  4189.  
  4190. .empty
  4191. .crapret    movea.l    (fb,pc),a1        ;file buffer
  4192.         bsr.w    FreeMemBlock
  4193.  
  4194. .skip        movea.l    MyPrefs,a0
  4195.         clr.b    (mhs_NewHiscore,a0)
  4196.         tst.b    (mhs_Valid,a0)    ;hi-scores loaded correctly?
  4197.         bne.s    .hsok
  4198.         bsr.w    ClearHighScores    ;no
  4199. .hsok
  4200.         bsr.w    CDBack
  4201.         rts
  4202.  
  4203.  
  4204. .hsc_CrapFile    lea    (crap_Text,pc),a1
  4205.         lea    (crap_Button,pc),a2
  4206.         bsr.w    InformationReq
  4207.         bra.s    .crapret
  4208.  
  4209. fb        dc.l    0
  4210. crap_Text    dc.b    '"Mines.hiscores" is crap.',10
  4211.         dc.b    'Will be overwritten on exit!',0
  4212. crap_Button    dc.b    'I see..',0
  4213.         cnop    0,4
  4214. ;*****************************************************************
  4215. CPL    = 80    ;chars per line
  4216. LOWC    = '¤'
  4217. MEDC    = 'ò'
  4218. HIGHC    = 'Ô'
  4219. PUTCH        MACRO
  4220.         move.b    \1,(a1)+
  4221.         addq.w    #1,d3
  4222.         subq.w    #1,d2
  4223.         bne.s    .cont\@
  4224.         addq.w    #1,d3
  4225.         move.w    #CPL,d2
  4226.         move.b    #10,(a1)+
  4227. .cont\@
  4228.         ENDM
  4229. ;------------------------------------------------------
  4230. SaveScore    ;IN: a3 - filename ;a4 - MyPrefs
  4231.         ;OUT: d0 - 0=OK
  4232.     ;alloc buffer
  4233.         move.l    #hsf_SIZEOF,d0
  4234.         moveq    #0,d1
  4235.         bsr.w    ADDALLOC
  4236.         tst.l    d0
  4237.         beq.w    ss_fail
  4238.         movea.l    d0,a5
  4239.     ;copy structure to buffer
  4240.         movea.l    a4,a0
  4241.         lea    (mhs_Data,a0),a0
  4242.         movea.l    a5,a1
  4243.         lea    (hsf_Data,a1),a1
  4244.         move.w    #DSIZEW-1,d0
  4245. .cp        move.w    (a0)+,(a1)+
  4246.         dbra    d0,.cp
  4247.     ;set EncodedChecksum
  4248.         movea.l    a5,a0
  4249.         lea    (hsf_Data,a0),a0
  4250.         moveq    #0,d0
  4251.         move.w    #DSIZEW-1,d1
  4252. .chck        add.w    (a0)+,d0
  4253.         dbra    d1,.chck
  4254.         move.w    d0,(hsf_DecodedChecksum,a5)
  4255.     ;set rndseed
  4256.         movea.l    IntuiBase,a0
  4257.         move.l    (ib_Micros,a0),d2
  4258.     ;code
  4259.         movea.l    a5,a0
  4260.         move.l    d2,(a0)    ;set rndseed to file
  4261.         lea    (hsf_Data,a0),a0        ;data
  4262.         move.w    #DSIZEW*2,d1    ;len
  4263.         bsr.w    Encrypt
  4264.     ;set coded checksum
  4265.         movea.l    a5,a0
  4266.         lea    (hsf_Data,a0),a0
  4267.         moveq    #0,d0
  4268.         move.w    #DSIZEW-1,d1
  4269. .chck2        add.w    (a0)+,d0
  4270.         dbra    d1,.chck2
  4271.         move.w    d0,(hsf_CodedChecksum,a5)
  4272.  
  4273.         move.w    LastXmas,(hsf_LastXmasYear,a5)
  4274.     ;save
  4275.     ;convert zmatky->txt
  4276.     ;low - <0-31>    med - <127-221>  high - <222-255>
  4277.     ;chr(10) is ignored (LF)
  4278.         move.l    #hsf_SIZEOF,d0    ;get max. size of hi-scores file
  4279.         add.l    d0,d0    ;*2 for e.G. '.A'
  4280.         move.l    d0,d1
  4281.         divu.l    #CPL,d1    ;LF's
  4282.         add.l    d1,d0
  4283.         moveq    #MEMF_PUBLIC,d1
  4284.         bsr.w    ADDALLOC
  4285.         move.l    d0,d7    ;store
  4286.         beq.w    ss_fail
  4287.  
  4288.         movea.l    d0,a0
  4289.         movea.l    a0,a1
  4290.         move.w    #hsf_SIZEOF-1,d1
  4291.         movea.l    a5,a0
  4292.         moveq    #0,d3        ;final size
  4293. .make0        moveq    #CPL,d2
  4294. .make        move.b    (a0)+,d0
  4295.  
  4296.         cmpi.b    #31,d0        ;check range
  4297.         bhi.s    .0
  4298.         PUTCH    #LOWC
  4299.         addi.b    #32,d0
  4300. .0        cmpi.b    #127,d0
  4301.         blo.s    .1
  4302.         cmpi.b    #221,d0
  4303.         bhi.s    .10
  4304.         PUTCH    #MEDC
  4305.         subi.b    #127-32,d0
  4306.         bra.s    .1
  4307. .10        PUTCH    #HIGHC
  4308.         subi.b    #222-32,d0
  4309. .1
  4310.         PUTCH    d0
  4311.         dbra    d1,.make
  4312.  
  4313.  
  4314.         move.l    a3,d0
  4315.         move.l    d7,d1
  4316.         move.l    d3,d2
  4317.         bsr.w    SAVE_FILE    ;IN: d0-filename;d1-data;d2-lenght;OUT: d0=0 => O.K.
  4318.         rts
  4319. ss_fail        moveq    #-1,d0
  4320.         rts
  4321. ;------------------------------------------
  4322. SaveHiScores    movem.l    d0-d7/a0-a6,-(sp)
  4323.         bsr.w    CDProggy
  4324.         movea.l    MyPrefs,a0
  4325.         lea    HsFileName,a3
  4326.         movea.l    MyPrefs,a4
  4327.         bsr.w    SaveScore
  4328.         tst.l    d0
  4329.         bne.s    save_fail
  4330.         clr.b    ([MyPrefs],mhs_NewHiscore)
  4331. shsc_exit
  4332.         bsr.w    CDBack
  4333.         movem.l    (sp)+,d0-d7/a0-a6
  4334.         rts
  4335.  
  4336. save_fail    lea    (.sf_Text,pc),a1
  4337.         lea    (.sf_Button,pc),a2
  4338.         bsr.w    InformationReq
  4339.         bra.s    shsc_exit
  4340.  
  4341. .sf_Text    dc.b    'Sorry. "Mines.hiscores" could not be saved.',0
  4342. .sf_Button    dc.b    'Oh, damned!',0
  4343.         cnop    0,4
  4344. ;-----------------------------------------
  4345. Decrypt    ;IN: a0-data, d1- length, d2-RndSeed
  4346.         movem.l    d0-d2/a0,-(sp)
  4347.         move.l    d2,RndSeed
  4348.         subq.w    #1,d1
  4349. .loop        move.b    (a0),d2
  4350.         moveq    #-1,d0
  4351.         bsr.w    Rand
  4352.         add.b    d0,d2
  4353.         move.b    d2,(a0)+
  4354.         dbra    d1,.loop
  4355.         movem.l    (sp)+,d0-d2/a0
  4356.         rts
  4357. Encrypt    ;IN: a0-data, d1-length, d2-RndSeed
  4358.         movem.l    d0-d2/a0,-(sp)
  4359.         move.l    d2,RndSeed
  4360.         subq.w    #1,d1
  4361. .loop        move.b    (a0),d2
  4362.         moveq    #-1,d0
  4363.         bsr.w    Rand
  4364.         sub.b    d0,d2
  4365.         move.b    d2,(a0)+
  4366.         dbra    d1,.loop
  4367.         movem.l    (sp)+,d0-d2/a0
  4368.         rts
  4369. *****************************************************************
  4370. DefaultPrefs    ;IN: a0-MyPrefs
  4371.         movem.l    d0/a0,-(sp)
  4372.         move.w    #prf_SIZEOF-1,d0
  4373. .clr        clr.b    (a0)+
  4374.         dbra    d0,.clr
  4375.         movem.l    (sp)+,d0/a0
  4376.         rts
  4377. ;-------------------------------------------------------------
  4378. LoadPreferences    ;Loads preferences from disk to memory.
  4379.         ;MyPrefs == ptr to PrefsBlock
  4380.  
  4381.         move.l    MyPrefs,d0
  4382.         bne.s    .ready
  4383.     ;**alloc memory for pref. structures
  4384.         move.l    #prf_SIZEOF,d0
  4385.         move.l    #0,d1
  4386.         bsr.w    ADDALLOC
  4387.         move.l    d0,MyPrefs
  4388.         beq.w    noprefs.fatal
  4389. .ready
  4390.     ;**set preferences to default
  4391.         movea.l    d0,a0
  4392.         bsr.w    DefaultPrefs
  4393.         lea    (error,pc),a0
  4394.         clr.b    (a0)
  4395.         lea    (diskObj,pc),a0
  4396.         clr.l    (a0)
  4397.     ;*get tool types
  4398.         movea.l    (EB,PC),a6
  4399.         lea    (IconName,pc),a1
  4400.         moveq    #MinIconVer,d0
  4401.         jsr    (_LVOOpenLibrary,a6)    ;"icon.library" V36
  4402.         lea    (IconBase,pc),a0
  4403.         move.l    d0,(a0)
  4404.         beq.s    noiconlib
  4405.  
  4406.         lea    ProgramName,a0
  4407.         movea.l    (IconBase,pc),a6
  4408.         jsr    (_LVOGetDiskObjectNew,a6)    ;get "mines.info" or something
  4409.         lea    (diskObj,pc),a0
  4410.         move.l    d0,(a0)
  4411.         beq.s    noobj        ;shouldn't happen...
  4412.         movea.l    d0,a0
  4413.         movea.l    (do_ToolTypes,a0),a4        ;get ToolTypes array
  4414.  
  4415.         lea    PrefItems,a3
  4416. .itloop        movea.l    a4,a0            ;tooltypes array
  4417.         move.l    (mpi_PItemName,a3),d0    ;tooltype name
  4418.         beq.s    .done
  4419.         movea.l    d0,a1
  4420.         movea.l    d0,a5        ;parameter for handlers
  4421.         jsr    (_LVOFindToolType,a6)
  4422.         tst.l    d0
  4423.         beq.s    .nextitem        ;not present
  4424.     ;call the mpi_PItemHandler
  4425.         movea.l    MyPrefs,a0    ;param
  4426.         movea.l    d0,a1
  4427.         movea.l    (mpi_PItemHandler,a3),a2
  4428.         movem.l    a3-a6,-(sp)
  4429.         jsr    (a2)
  4430.         movem.l    (sp)+,a3-a6
  4431.  
  4432. .nextitem    lea    (mpi_SIZEOF,a3),a3
  4433.         bra.s    .itloop
  4434. .done
  4435.  
  4436.     ;check mprf_Custom(s)
  4437. TESTCUSTOM    MACRO
  4438.         tst.w    (mprf_Custom\1,a0)
  4439.         bne.s    .ok\@
  4440.         move.w    (cpf_\1,a1),(mprf_Custom\1,a0)
  4441. .ok\@
  4442.         ENDM
  4443.  
  4444.         movea.l    MyPrefs,a0
  4445.         lea    CusPFSizes,a1
  4446.         TESTCUSTOM    Width
  4447.         TESTCUSTOM    Height
  4448.         TESTCUSTOM    Bombs
  4449.  
  4450.         movea.l    (diskObj,pc),a0
  4451.         jsr    (_LVOFreeDiskObject,a6)
  4452. noobj        move.l    (EB,PC),a6
  4453.         movea.l    (IconBase,pc),a1
  4454.         jsr    (_LVOCloseLibrary,a6)
  4455.  
  4456. exitprefs
  4457.         rts
  4458.  
  4459. ;-------------------------------------------
  4460. noprefs.fatal    lea    noprefs_Text,a1
  4461.         lea    noprefs_Button,a2
  4462.         bsr.w    InformationReq
  4463.         bra.s    exitprefs
  4464. noiconlib    lea    (noicon_Text,pc),a1
  4465.         lea    (noicon_Button,pc),a2
  4466.         bsr.w    InformationReq
  4467.         bra.s    exitprefs
  4468.  
  4469. errBuf        dc.l    0
  4470. diskObj        dc.l    0
  4471. IconBase    dc.l    0
  4472. IconName    dc.b    'icon.library',0
  4473. noicon_Text    dc.b    '"icon.library" V36+ required to load preferences',0
  4474. noicon_Button    dc.b    'Continue',0
  4475. error        dc.b    0
  4476.         even
  4477.  
  4478. ;****Some small subroutines-------------------------------
  4479. uppercaseD0    cmpi.b    #'a',d0
  4480.         blo.s    .noup
  4481.         cmpi.b    #'z',d0
  4482.         bhi.s    .noup
  4483.         subi.b    #'a'-'A',d0
  4484. .noup        rts
  4485.  
  4486. ;*******Preference items handlers**************************************
  4487. ;They're called with MyPrefs pointer in A0
  4488. ;A1 contains address of next char to read (the parameter)
  4489. ;a4-tooltypes array, a5-tooltype name, a6-IconBase
  4490.  
  4491. ;---------------------------------------------
  4492. Pref_PubScreen    move.l    a1,a3
  4493.         moveq    #0,d0
  4494.  
  4495. .count        tst.b    (a1)+
  4496.         beq.s    .end
  4497.         addq.w    #1,d0
  4498.         bra.s    .count
  4499. .end        tst.l    d0        ;no name after PUBSCREEN
  4500.         beq.s    .skip0
  4501.         addq.w    #1,d0
  4502.         moveq    #MEMF_PUBLIC,d1
  4503.         bsr.w    ADDALLOC
  4504. .skip0        movea.l    a3,a1
  4505.         move.l    d0,(mprf_PubNameAdr,a0)
  4506.         beq.s    .skip
  4507.         movea.l    d0,a2
  4508. .cp        move.b    (a1)+,(a2)+
  4509.         bne.s    .cp
  4510. .skip
  4511.         rts
  4512. ;---------------------------------------------
  4513. Pref_ModeID    movea.l    a1,a2        ;store
  4514.         bsr.w    NumConvert
  4515.         tst.l    d1
  4516.         bne.w    errNum
  4517.         move.l    d0,(mprf_ModeID,a0)
  4518.         rts
  4519. ;---------------------------------------------
  4520. Pref_SizeX    movea.l    a1,a2        ;store
  4521.         bsr.w    NumConvert
  4522.         tst.l    d1
  4523.         bne.w    errNum
  4524.         move.l    #NUMF_WORD!NUMF_PLUS!NUMF_NONZERO,d1
  4525.         bsr.w    CheckNum
  4526.         tst.l    d1
  4527.         bne.w    errVal
  4528.         move.w    d0,(mprf_ScrWidth,a0)
  4529.         rts
  4530. ;---------------------------------------------
  4531. Pref_SizeY    movea.l    a1,a2        ;store
  4532.         bsr.w    NumConvert
  4533.         tst.l    d1
  4534.         bne.w    errNum
  4535.         move.l    #NUMF_WORD!NUMF_PLUS!NUMF_NONZERO,d1
  4536.         bsr.w    CheckNum
  4537.         tst.l    d1
  4538.         bne.w    errVal
  4539.         move.w    d0,(mprf_ScrHeight,a0)
  4540.         rts
  4541. ;---------------------------------------------
  4542. Pref_CustomScreen
  4543.         move.b    #TRUE,(mprf_CustomScreen,a0)
  4544.         rts
  4545. ;---------------------------------------------
  4546. Pref_WBLike    move.b    #TRUE,(mprf_WBLike,a0)
  4547.         rts
  4548. ;---------------------------------------------
  4549. Pref_NotCenter    move.b    #TRUE,(mprf_CenterWindow,a0)    ;CenterWindow=no
  4550.         rts
  4551. ;---------------------------------------------
  4552. Pref_NotActiv    move.b    #TRUE,(mprf_WActivate,a0)
  4553.         rts
  4554. ;---------------------------------------------
  4555. Pref_NoQuest    move.b    #TRUE,(mprf_Question,a0)
  4556.         rts
  4557. ;---------------------------------------------
  4558. Pref_DeadQ    move.b    #TRUE,(mprf_DeadQ,a0)
  4559.         rts
  4560. ;---------------------------------------------
  4561. Pref_NoRMouse    move.b    #TRUE,(mprf_RMouseGame,a0)
  4562.         rts
  4563. ;---------------------------------------------------------
  4564. Pref_Warn    move.b    #TRUE,(mprf_Warn,a0)    ;TRUE=DONOTWARN
  4565.         rts
  4566. ;---------------------------------------------
  4567. Pref_CountD    move.b    #TRUE,(mprf_CountDown,a0)
  4568.         rts
  4569. ;---------------------------------------------
  4570. Pref_Scale    move.b    #TRUE,(mprf_ScaleGfx,a0)
  4571.         rts
  4572. ;---------------------------------------------
  4573. Pref_WinX    movea.l    a1,a2        ;store
  4574.         bsr.w    NumConvert
  4575.         tst.l    d1
  4576.         bne.w    errNum
  4577.         move.l    #NUMF_WORD,d1    ;check the number type
  4578.         bsr.w    CheckNum
  4579.         tst.l    d1
  4580.         bne.w    errVal
  4581.         move.w    d0,(mprf_WinX,a0)
  4582.         rts
  4583. ;---------------------------------------------
  4584. Pref_WinY    movea.l    a1,a2        ;store
  4585.         bsr.w    NumConvert
  4586.         tst.l    d1
  4587.         bne.w    errNum
  4588.         move.l    #NUMF_WORD,d1
  4589.         bsr.w    CheckNum
  4590.         tst.l    d1
  4591.         bne.w    errVal
  4592.         move.w    d0,(mprf_WinY,a0)
  4593.         rts
  4594. ;---------------------------------------------
  4595. Pref_ZoomX    movea.l    a1,a2
  4596.         bsr.w    NumConvert
  4597.         tst.l    d1
  4598.         bne.w    errNum
  4599.         move.l    #NUMF_WORD,d1
  4600.         bsr.w    CheckNum
  4601.         tst.l    d1
  4602.         bne.w    errVal
  4603.         move.w    d0,(mprf_ZoomLeft,a0)
  4604.         move.w    d0,ZoomParams
  4605.         rts
  4606. ;---------------------------------------------
  4607. Pref_ZoomY    movea.l    a1,a2
  4608.         bsr.w    NumConvert
  4609.         tst.l    d1
  4610.         bne.w    errNum
  4611.         move.l    #NUMF_WORD,d1
  4612.         bsr.w    CheckNum
  4613.         tst.l    d1
  4614.         bne.w    errVal
  4615.         move.w    d0,(mprf_ZoomTop,a0)
  4616.         move.w    d0,ZoomParams+2
  4617.         rts
  4618. ;---------------------------------------------
  4619.     ;**Set level
  4620. CHECKLEV    MACRO
  4621.         movea.l    a2,a0        ;tooltype value
  4622.         lea    (tt\1,pc),a1
  4623.         jsr    (_LVOMatchToolValue,a6)
  4624.         tst.l    d0
  4625.         beq.s    .no\@
  4626.         movea.l    (sp)+,a0
  4627.         move.b    #L\1,(mprf_Level,a0)
  4628.         bra.s    .exit
  4629. .no\@
  4630.         ENDM
  4631.  
  4632. Pref_Level    move.l    a0,-(sp)
  4633.         movea.l    a1,a2        ;store
  4634.  
  4635.         CHECKLEV EASY
  4636.         CHECKLEV MEDIUM
  4637.         CHECKLEV HARD
  4638.         CHECKLEV PROFI
  4639.         CHECKLEV CUSTOM
  4640.         lea    (errlev_Text,pc),a1
  4641.         bsr.w    ToolTypesError
  4642.         addq.l    #4,sp
  4643. .exit        rts
  4644.  
  4645. ttEASY    dc.b    'EASY',0
  4646. ttMEDIUM dc.b    'MEDIUM',0
  4647. ttHARD    dc.b    'HARD',0
  4648. ttPROFI    dc.b    'PROFI',0
  4649. ttCUSTOM dc.b    'CUSTOM',0
  4650. errlev_Text    dc.b    'Unknown level definition.',10
  4651.         dc.b    'Medium level used.',0
  4652.         cnop    0,4
  4653.  
  4654. ;---------------------------------------------
  4655. Pref_CusWid    movea.l    a1,a2        ;store
  4656.         bsr.w    NumConvert
  4657.         tst.l    d1
  4658.         bne.w    errNum
  4659.         move.l    #NUMF_WORD!NUMF_NONZERO!NUMF_PLUS,d1
  4660.         bsr.w    CheckNum
  4661.         tst.l    d1
  4662.         bne.w    errVal
  4663.         move.w    d0,CusPFSizes+cpf_Width
  4664.         move.w    d0,(mprf_CustomWidth,a0)
  4665.         rts
  4666. ;---------------------------------------------
  4667. Pref_CusHei    movea.l    a1,a2        ;store
  4668.         bsr.w    NumConvert
  4669.         tst.l    d1
  4670.         bne.w    errNum
  4671.         move.l    #NUMF_WORD!NUMF_NONZERO!NUMF_PLUS,d1
  4672.         bsr.w    CheckNum
  4673.         tst.l    d1
  4674.         bne.w    errVal
  4675.         move.w    d0,CusPFSizes+cpf_Height
  4676.         move.w    d0,(mprf_CustomHeight,a0)
  4677.         rts
  4678. ;---------------------------------------------
  4679. Pref_CusBom    movea.l    a1,a2        ;store
  4680.         bsr.w    NumConvert
  4681.         tst.l    d1
  4682.         bne.w    errNum
  4683.         move.l    #NUMF_WORD!NUMF_NONZERO!NUMF_PLUS,d1
  4684.         bsr.w    CheckNum
  4685.         tst.l    d1
  4686.         bne.w    errVal
  4687.         move.w    d0,CusPFSizes+cpf_Bombs
  4688.         move.w    d0,(mprf_CustomBombs,a0)
  4689.         rts
  4690. ;---------------------------------------------
  4691. Pref_Font
  4692.     ;**check if font=DEFAULT
  4693.         movem.l    a0/a1,-(sp)    ;store
  4694.         movea.l    a1,a0    ;returned by FindToolType
  4695.         lea    (defaultText,pc),a1
  4696.         jsr    (_LVOMatchToolValue,a6)
  4697.         movem.l    (sp)+,a0/a1
  4698.  
  4699.         tst.l    d0
  4700.         bne.s    .default
  4701.     ;**copy font name to a buffer
  4702.         lea    MyFontName,a2    ;buffer (30 chars)
  4703.         move.l    a2,d0
  4704.         moveq    #30-1,d1    ;max 30 chars
  4705. .loop        move.b    (a1)+,(a2)+    ;copy font name
  4706.         dbeq    d1,.loop
  4707.         tst.b    MyFontName    ;no name specified in tool types
  4708.         beq.w    .exit
  4709.         move.l    d0,(mprf_FontName,a0)
  4710. .exit        rts
  4711. .default    clr.l    (mprf_FontName,a0)
  4712.         rts
  4713.  
  4714. defaultText    dc.b    'DEFAULT',0
  4715.         cnop    0,4
  4716. ;---------------------------------------------
  4717. Pref_FontSize
  4718.         movea.l    a1,a2        ;store
  4719.     ;**check if Fontsize=DESIGNED
  4720.         movem.l    a0/a1,-(sp)    ;store
  4721.         movea.l    a1,a0    ;returned by FindToolType
  4722.         lea    (designedText,pc),a1
  4723.         jsr    (_LVOMatchToolValue,a6)
  4724.         movem.l    (sp)+,a0/a1    ;restore
  4725.  
  4726.         tst.l    d0
  4727.         bne.s    .designed
  4728.  
  4729.         bsr.w    NumConvert
  4730.         tst.l    d1
  4731.         bne.w    errNum
  4732.         move.l    #NUMF_WORD!NUMF_NONZERO!NUMF_PLUS,d1
  4733.         bsr.w    CheckNum
  4734.         tst.l    d1
  4735.         bne.w    errVal
  4736.         move.w    d0,(mprf_FontSize,a0)
  4737.         rts
  4738. .designed    clr.w    (mprf_FontSize,a0)    ;font size of zero means DESIGNED
  4739.         rts
  4740.  
  4741. designedText    dc.b    'DESIGNED',0
  4742.         cnop    0,4
  4743. ;---------------------------------------------
  4744. Pref_Iconify    ;check for ICON,MENU
  4745.         movea.l    a1,a2
  4746.         movea.l    a0,a3
  4747.         movea.l    a2,a0
  4748.         lea    (iconIcon,pc),a1
  4749.         jsr    (_LVOMatchToolValue,a6)
  4750.         tst.l    d0
  4751.         bne.s    .icon
  4752.  
  4753.         movea.l    a2,a0
  4754.         lea    (iconMenu,pc),a1
  4755.         jsr    (_LVOMatchToolValue,a6)
  4756.         tst.l    d0
  4757.         bne.s    .menu
  4758.  
  4759.         lea    (badicon_Text,pc),a1
  4760.         bsr.w    ToolTypesError
  4761. .icon        move.b    #ICON_ICON,(mprf_Iconify,a3)
  4762.         rts
  4763. .menu        move.b    #ICON_MENU,(mprf_Iconify,a3)
  4764.         rts
  4765.  
  4766. badicon_Text    dc.b    'Only MENU or ICON allowed.',10
  4767.         dc.b    'Now ICON used.',0
  4768. iconMenu    dc.b    'MENU',0
  4769. iconIcon    dc.b    'ICON',0
  4770.         cnop    0,4
  4771. ;---------------------------------------------
  4772. Pref_GfxType
  4773.     ;check for STANDARD/MagicWB
  4774.         movea.l    a1,a2
  4775.         movea.l    a0,a3
  4776.         movea.l    a2,a0
  4777.         lea    (gfxStandard,pc),a1
  4778.         jsr    (_LVOMatchToolValue,a6)
  4779.         tst.l    d0
  4780.         bne.s    .stdgfx
  4781.         movea.l    a2,a0
  4782.         lea    (gfxMagicWB,pc),a1
  4783.         jsr    (_LVOMatchToolValue,a6)
  4784.         tst.l    d0
  4785.         bne.s    .magwbgfx
  4786.  
  4787.         lea    (badgfx_Text,pc),a1
  4788.         bsr.w    ToolTypesError
  4789.  
  4790. .stdgfx        move.b    #GFX_STANDARD,(mprf_GfxType,a3)
  4791.         rts
  4792.  
  4793. .magwbgfx    move.b    #GFX_MAGICWB,(mprf_GfxType,a3)
  4794.         rts
  4795.  
  4796. gfxStandard    dc.b    'STANDARD',0
  4797. gfxMagicWB    dc.b    'MAGICWB',0
  4798. badgfx_Text    dc.b    'Type of requested gfx not supported.',10
  4799.         dc.b    'Standard gfx used.',0
  4800.         cnop    0,4
  4801. ;---------------------------------------------
  4802. Pref_Palette
  4803.     ;check for STANDARD/MAGICWB/WBLIKE
  4804.         movea.l    a1,a2
  4805.         movea.l    a2,a0
  4806.         lea    (ptStandard,pc),a1
  4807.         jsr    (_LVOMatchToolValue,a6)
  4808.         tst.l    d0
  4809.         bne.w    Pref_PaletteStd
  4810.  
  4811.         movea.l    a2,a0
  4812.         lea    (ptMagicWB,pc),a1
  4813.         jsr    (_LVOMatchToolValue,a6)
  4814.         tst.l    d0
  4815.         bne.w    Pref_PaletteMag
  4816.  
  4817.         movea.l    a2,a0
  4818.         lea    (ptWBLike,pc),a1
  4819.         jsr    (_LVOMatchToolValue,a6)
  4820.         tst.l    d0
  4821.         bne.w    Pref_PaletteWB
  4822.     ;else colortable defined palette
  4823.         move.b    #PAL_COLORTABLE,([MyPrefs],mprf_PaletteType)
  4824.         movea.l    a2,a1
  4825.         lea    ScreenPalette+4,a3    ;skip first 2 words
  4826.         moveq    #PALENTRIES-1,d6
  4827. .go        bsr.w    NumConvert    ;convert next palette entry
  4828.         tst.l    d1
  4829.         bne.s    errPalette
  4830.         move.l    #NUMF_LONG!NUMF_PLUS,d1
  4831.         bsr.w    CheckNum
  4832.         tst.l    d1
  4833.         bne.s    errPalette
  4834.  
  4835.     ;convert to LoadRGB32 format
  4836. EXTANDSAVE    MACRO
  4837.         bfins    d1,d1{16:8}
  4838.         bfins    d1,d1{8:8}
  4839.         bfins    d1,d1{0:8}
  4840.         move.l    d1,(a3)+    ;save entry
  4841.         ENDM
  4842.  
  4843.         bfextu    d0{8:8},d1    ;RED
  4844.         EXTANDSAVE
  4845.         bfextu    d0{16:8},d1    ;GREEN
  4846.         EXTANDSAVE
  4847.         bfextu    d0{24:8},d1    ;BLUE
  4848.         EXTANDSAVE
  4849.  
  4850. .seek        move.b    (a1)+,d0    ;seek to next entry (",")
  4851.         beq.s    .ready        ;zero=eol
  4852.         cmpi.b    #',',d0
  4853.         bne.s    .seek
  4854.         dbra    d6,.go
  4855. .ready
  4856.         rts
  4857.  
  4858. errPalette
  4859.         lea    (errpal_Text,pc),a1
  4860.         lea    (errpal_Button,pc),a2
  4861.         bsr.w    InformationReq
  4862.         ;no rts!
  4863.  
  4864. ;----------
  4865. Pref_PaletteStd    move.b    #PAL_STANDARD,([MyPrefs],mprf_PaletteType)
  4866.         lea    DefaultPalette,a2    ;copy once again
  4867. CopyPalette    lea    ScreenPalette,a3
  4868.         moveq    #PALENTRIES*3+2-1,d0
  4869. .loop        move.l    (a2)+,(a3)+
  4870.         dbra    d0,.loop
  4871.         rts
  4872.  
  4873. ;----------
  4874. Pref_PaletteMag    move.b    #PAL_MAGICWB,([MyPrefs],mprf_PaletteType)
  4875.         lea    MagicPalette,a2
  4876.         bra.s    CopyPalette
  4877.  
  4878. ;----------
  4879. Pref_PaletteWB    move.b    #PAL_WBLIKE,([MyPrefs],mprf_PaletteType)
  4880.         movea.l    IntuiBase,a6
  4881.         lea    wbName,a0
  4882.         jsr    (_LVOLockPubScreen,a6)    ;lock Workbench
  4883.         lea    (lockedWB,pc),a0
  4884.         move.l    d0,(a0)
  4885.         beq.s    Pref_PaletteStd        ;couldn't lock WB
  4886.         movea.l    d0,a0
  4887.  
  4888.         movea.l    (sc_ViewPort+vp_ColorMap,a0),a0    ;cm
  4889.         moveq    #0,d0                ;first colors
  4890.         moveq    #PALENTRIES,d1            ;n-colors
  4891.         lea    ScreenPalette+4,a1        ;table
  4892.         movea.l    _GfxBase,a6
  4893.         jsr    (_LVOGetRGB32,a6)
  4894.  
  4895.         movea.l    IntuiBase,a6
  4896.         suba.l    a0,a0
  4897.         movea.l    (lockedWB,pc),a1
  4898.         jsr    (_LVOUnlockPubScreen,a6)    ;unlock WB
  4899.         rts
  4900.  
  4901. lockedWB    dc.l    0
  4902. ptStream    dc.l    0,0
  4903. ptStandard    dc.b    'STANDARD',0
  4904. ptMagicWB    dc.b    'MAGICWB',0
  4905. ptWBLike    dc.b    'WBLIKE',0
  4906. errpal_Text    dc.b    'Error in palette definition.',10
  4907.         dc.b    '(See Tool Types)',10
  4908.         dc.b    'Standard palette used.',0
  4909. errpal_Button    dc.b    'I',39,'ll have a look.',0
  4910.  
  4911.         cnop    0,4
  4912. ;---------------------------------------------------------
  4913. errNum        ;number expected
  4914.         ;IN:a5-tooltype name  a2-tooltype value
  4915.         lea    (noval_Text,pc),a1
  4916.         bsr.w    ToolTypesError
  4917.         rts
  4918. errVal        ;invalid value found
  4919.         ;IN:a5-tool type name  a2-tooltype val.
  4920.         lea    (badval_Text,pc),a1
  4921.         bsr.w    ToolTypesError
  4922.         rts
  4923.  
  4924. noval_Text    dc.b    'Number expected.',0
  4925. badval_Text    dc.b    'Invalid value defined.',0
  4926.         cnop    0,4
  4927. ;----------------------------------------------------------------
  4928. ToolTypesError    ;IN:a1-explain text  a5-tooltype name  a2-tooltype param.
  4929.         movem.l    d1-d7/a0-a6,-(sp)
  4930.         lea    (tte_argarray,pc),a4
  4931.         move.l    a5,(a4)
  4932.         move.l    a2,(4,a4)
  4933.         move.l    a1,(8,a4)
  4934.         lea    (tte_Text,pc),a1
  4935.         lea    (tte_Button,pc),a2
  4936.         movea.l    _ReqToolsBase,a6
  4937.         suba.l    a3,a3
  4938.         lea    IReqTags,a0
  4939.         jsr    (_LVOrtEZRequestA,a6)
  4940.         movem.l    (sp)+,d1-d7/a0-a6
  4941.         rts
  4942.  
  4943. tte_argarray    dc.l    0,0,0
  4944. tte_Text    dc.b    'Error in Tool Types.',10
  4945.         dc.b    '"%s=%s"',10,'%s',0
  4946. tte_Button    dc.b    'I',39,'ll have a look.',0
  4947.         cnop    0,4
  4948. ;----------------------------------------------------------------
  4949. CheckNum    ;checkes the LONG number in d0 if it matches
  4950.         ;the flags in d1
  4951.         ;RESULTS: d1.l=0 => O.K. else error
  4952. ;NUMF_BYTE    = 1    ;not implemented
  4953. NUMF_LONG    = 0    ;this is default
  4954. NUMF_WORD    = 1<<2
  4955.  
  4956. NUMF_NONZERO    = 1<<6    ;values != 0
  4957. NUMF_PLUS    = 1<<7    ;values >= 0
  4958. NUMF_MINUS    = 1<<8    ;<0
  4959.  
  4960.         move.l    d1,d2
  4961.         andi.l    #NUMF_WORD,d2
  4962.         beq.s    .next
  4963.         move.w    d0,d3        ;do not touch d0
  4964.         ext.l    d3
  4965.         cmp.l    d0,d3
  4966.         bne.s    cn_NotMatch
  4967.  
  4968.         move.l    d1,d2
  4969.         andi.l    #NUMF_NONZERO,d2    ;test for non zero?
  4970.         beq.s    .nextw2            ;no
  4971.         tst.l    d0
  4972.         beq.s    cn_NotMatch
  4973. .nextw2        move.l    d1,d2
  4974.         andi.l    #NUMF_PLUS,d2
  4975.         beq.s    .nextw3
  4976.         tst.w    d0
  4977.         bmi.s    cn_NotMatch
  4978. .nextw3        move.l    d1,d2
  4979.         andi.l    #NUMF_MINUS,d2
  4980.         beq.s    .Matched
  4981.         tst.w    d0
  4982.         bpl.s    cn_NotMatch
  4983.         bra.s    .Matched
  4984.  
  4985.     ;next is for LONG
  4986. .next        move.l    d1,d2
  4987.         andi.l    #NUMF_NONZERO,d2    ;test for non zero?
  4988.         beq.s    .next2            ;no
  4989.         tst.l    d0
  4990.         beq.s    cn_NotMatch
  4991. .next2        move.l    d1,d2
  4992.         andi.l    #NUMF_PLUS,d2
  4993.         beq.s    .next3
  4994.         tst.l    d0
  4995.         bmi.s    cn_NotMatch
  4996. .next3        move.l    d1,d2
  4997.         andi.l    #NUMF_MINUS,d2
  4998.         beq.s    .Matched
  4999.         tst.l    d0
  5000.         bpl.s    cn_NotMatch
  5001. .Matched
  5002.         moveq    #0,d1        ;matched
  5003.         rts
  5004. cn_NotMatch    moveq    #-1,d1
  5005.         rts
  5006. ;***********************************************************
  5007. NumConvert    ;in a1-pointer to an ASCII number terminated by zero byte
  5008.         ;or by a ","
  5009.         ;examples: -246, 3467, 0xfc3A, $D34e, -&H1, &h23F
  5010.         ;Octal and binar numbers are not handled
  5011.         ;results in d0.l, if d1.l=0 then succes else error
  5012.  
  5013.         move.l    a2,-(sp)    ;store
  5014.     ;**find out sign
  5015.         clr.b    Sign    ;plus
  5016.         cmpi.b    #'-',(a1)
  5017.         bne.s    .plus
  5018.         st    Sign
  5019.         bra.s    .skip
  5020. .plus        cmpi.b    #'+',(a1)
  5021.         bne.s    mpok
  5022. .skip        addq.w    #1,a1    ;skip sign
  5023. mpok
  5024.     ;**find out about the type  (DEC/HEX available at the moment...)
  5025.         movea.l    a1,a2        ;seek to end and uppercase
  5026. .loop        move.b    (a2),d0
  5027.         bsr.w    uppercaseD0
  5028.         move.b    d0,(a2)+
  5029.         cmpi.b    #',',d0
  5030.         beq.s    .1
  5031.         tst.b    d0
  5032.         bne.s    .loop
  5033. .1        subq.w    #1,a2        ;points to the end byte
  5034.  
  5035.         cmpa.l    a1,a2
  5036.         beq.w    nc_invalid    ;just no number there
  5037.  
  5038.         move.b    (a1),d1
  5039.         move.w    (a1),d2
  5040.  
  5041.         cmpi.b    #'$',d1
  5042.         beq.s    nc_hex1
  5043.         cmpi.w    #'&H',d2
  5044.         beq.s    nc_hex2
  5045.         cmpi.w    #'0X',d2
  5046.         beq.s    nc_hex2
  5047.     ;else decimal
  5048. nc_dec        moveq    #1,d2    ;10^0 .. 10^1 .. 10^2 ..
  5049.         moveq    #0,d0    ;result
  5050. .decLoop    move.b    -(a2),d1
  5051.         cmpi.b    #'0',d1        ;is the char in range 0-9
  5052.         blo.s    nc_invalid    ;no
  5053.         cmpi.b    #'9',d1
  5054.         bhi.s    nc_invalid    ;no
  5055.         subi.b    #'0',d1
  5056.         extb    d1
  5057.         mulu.l    d2,d1        ;d1:=d1*10^x
  5058.         add.l    d1,d0
  5059.         bvs.s    nc_invalid    ;overflow?
  5060.         mulu.l    #10,d2
  5061.         bvs.s    nc_invalid
  5062.         cmpa.l    a2,a1
  5063.         bne.s    .decLoop
  5064.         moveq    #0,d1        ;succes
  5065.         bra.s    SignTest
  5066.  
  5067. nc_hex2        addq.w    #1,a1    ;skip '&H' '0X'
  5068. nc_hex1        addq.w    #1,a1    ;skip '$'
  5069.         moveq    #0,d0
  5070.         moveq    #31-3,d2
  5071. .hexLoop    move.b    -(a2),d1
  5072.         cmpi.b    #'0',d1        ;test range (0..9)
  5073.         blo.s    nc_invalid
  5074.         cmpi.b    #'9',d1
  5075.         bls.s    .ok
  5076.  
  5077.         cmpi.b    #'A',d1        ;test (A..F)
  5078.         blo.s    nc_invalid
  5079.         cmpi.b    #'F',d1
  5080.         bhi.s    nc_invalid
  5081.         subi.b    #'A'-'9'-1,d1
  5082. .ok        subi.b    #'0',d1
  5083.         bfins    d1,d0{d2:4}
  5084.         cmpa.l    a1,a2
  5085.         beq.s    nc_HexReady
  5086.         subq.w    #4,d2        ;next nibble
  5087.         bpl.s    .hexLoop    ;exit if out of longword
  5088. nc_HexReady    moveq    #0,d1        ;succes
  5089.  
  5090. SignTest    tst.b    Sign
  5091.         beq.s    .ok
  5092.         neg.l    d0
  5093. .ok        movea.l    (sp)+,a2
  5094.         rts
  5095.  
  5096. nc_invalid    moveq    #-1,d1    ;error
  5097.         moveq    #0,d0
  5098.         movea.l    (sp)+,a2
  5099.         rts
  5100. ;*****************************************************************
  5101. GetScreenCenter    ;gets center of the visible part of screen
  5102.         movea.l    MyScreen,a5
  5103.     ;get screen and window sizes
  5104.         movea.l    (sc_ViewPort+vp_ColorMap,a5),a4
  5105.         movea.l    (cm_vpe,a4),a4    ;ViewPortExtra
  5106.     ;Winx=(ScrWidth-WinWidth)/2
  5107.         move.w    (vpe_DisplayClip+ra_MaxX,a4),d1
  5108.         sub.w    (vpe_DisplayClip+ra_MinX,a4),d1
  5109.         move.w    (sc_Width,a5),d0
  5110.         cmp.w    d0,d1        ;if screen width < display clip
  5111.         bls.s    .dc1
  5112.         move.w    d0,d1
  5113. .dc1        asr.w    #1,d1    ;/2
  5114.         sub.w    (sc_ViewPort+vp_DxOffset,a5),d1    ;offset
  5115.         move.w    d1,CenterPointX
  5116.  
  5117.     ;WinY=(ScrHeight-WinHeight)/2
  5118.         move.w    (vpe_DisplayClip+ra_MaxY,a4),d1
  5119.         sub.w    (vpe_DisplayClip+ra_MinY,a4),d1
  5120.         move.w    (sc_Height,a5),d0
  5121.         cmp.w    d0,d1
  5122.         bls.s    .dc2
  5123.         move.w    d0,d1
  5124. .dc2        asr.w    #1,d1    ;/2
  5125.         sub.w    (sc_ViewPort+vp_DyOffset,a5),d1
  5126.         move.w    d1,CenterPointY
  5127.         rts
  5128.  
  5129. ;*****************************************************************
  5130. SetWinParams    ;sets the required window size and placement
  5131.  
  5132.     ;**Get the PlayField size
  5133. .prefs        movea.l    MyPrefs,a0
  5134.         move.b    (mprf_Level,a0),d0
  5135.         bne.s    .cont
  5136.         move.b    #LMEDIUM,d0
  5137.         move.b    d0,(mprf_Level,a0)
  5138. .cont        lea    DefPFSizes,a0
  5139.         ext.w    d0
  5140.         move.w    (a0,d0.w*8),PFWidth
  5141.         move.w    (2,a0,d0.w*8),PFHeight
  5142.         move.w    (4,a0,d0.w*8),PFBombs
  5143.  
  5144.         clr.b    d5
  5145.     ;check for minimal height
  5146.         cmpi.w    #MINPFHEIGHT,PFHeight
  5147.         bhs.s    .cw
  5148.         move.w    #MINPFHEIGHT,PFHeight
  5149.         move.w    #MINPFHEIGHT,(2,a0,d0.w*8)
  5150.         move.w    #MINPFHEIGHT,([MyPrefs],mprf_CustomHeight)
  5151.         move.w    d0,-(sp)        ;store
  5152.         lea    toosmall_Text,a1
  5153.         lea    toosmall_Button,a2
  5154.         bsr.w    InformationReq
  5155.         move.w    (sp)+,d0
  5156.         st    d5            ;set flag
  5157.     ;check for minimal width
  5158. .cw        move.w    MinRowBut,d1
  5159.         cmp.w    PFWidth,d1
  5160.         bls.s    .well
  5161.         move.w    d1,(a0,d0.w*8)
  5162.         move.w    d1,([MyPrefs],mprf_CustomWidth)
  5163.         move.w    d1,PFWidth
  5164.         tst.b    d5
  5165.         bne.s    .well        ;don't bother with messages anymore
  5166.         move.w    d0,-(sp)        ;store
  5167.         lea    toosmall_Text,a1
  5168.         lea    toosmall_Button,a2
  5169.         bsr.w    InformationReq
  5170.         move.w    (sp)+,d0
  5171. .well
  5172.         move.w    PFWidth,d1        ;check for maximum mines
  5173.         mulu.w    PFHeight,d1
  5174.         subq.w    #1,d1
  5175.         cmp.w    PFBombs,d1
  5176.         bhs.s    .tmok
  5177.         move.w    d1,(4,a0,d0.w*8)
  5178.         move.w    d1,([MyPrefs],mprf_CustomBombs)
  5179.         move.w    d1,PFBombs
  5180.         lea    toomuch_Text,a1
  5181.         lea    toomuch_Button,a2
  5182.         bsr.w    InformationReq
  5183. .tmok
  5184.  
  5185.         addq.w    #2,PFWidth
  5186.         addq.w    #2,PFHeight
  5187.  
  5188.  
  5189.     ;**Set window size
  5190.         move.w    ButtHeight,d0    ;my bar size
  5191.         add.w    d0,d0
  5192.         move.w    d0,MyBarHeight
  5193.  
  5194.         move.w    PFWidth,d0    ;Inner sizes
  5195.         subq.w    #2,d0
  5196.         mulu.w    ButtWidth,d0
  5197.         move.w    d0,InnWidth
  5198.         move.w    PFHeight,d0
  5199.         subq.w    #2,d0
  5200.         mulu.w    ButtHeight,d0
  5201.         add.w    MyBarHeight,d0
  5202.         move.w    d0,InnHeight
  5203.  
  5204. setWsize    movea.l    MyScreen,a0
  5205.         moveq    #0,d2
  5206.         move.w    d2,d3
  5207.         move.w    d2,d4
  5208.         move.w    d2,d5
  5209.         move.b    (sc_WBorLeft,a0),d2
  5210.         move.b    (sc_WBorRight,a0),d3
  5211.         move.b    (sc_WBorTop,a0),d4
  5212.         add.w    ([sc_Font,a0],ta_YSize),d4
  5213.         addq.w    #1,d4
  5214.         move.w    d4,winBarH
  5215.         move.b    (sc_WBorBottom,a0),d5
  5216.  
  5217.         move.w    InnWidth,d0    ;width
  5218.         add.w    d2,d0        ;BorderLeft
  5219.         add.w    d3,d0        ;      Right
  5220.         move.w    d0,WinWidth
  5221.  
  5222.         move.w    InnHeight,d0    ;height
  5223.         add.w    d4,d0        ;BorderTop
  5224.         add.w    d5,d0        ;      Bottom
  5225.         move.w    d0,WinHeight
  5226.  
  5227.         move.w    d2,MinX
  5228.         move.w    d2,MinPFX    ;(for future?)
  5229.         move.w    d4,MinY
  5230.         add.w    MyBarHeight,d4
  5231.         move.w    d4,MinPFY
  5232.  
  5233.     ;**Check if window is bigger than screen
  5234.         movea.l    MyScreen,a5
  5235.         move.w    WinWidth,d0
  5236.         cmp.w    (sc_Width,a5),d0    ;d0<=sc_Width?
  5237.         bls.s    .skip
  5238.         move.w    (sc_Width,a5),WinWidth    ;validate
  5239.         st    Disable
  5240.         st    DisplayTooBig    ;inform the user
  5241.     ;  set new InnWidth
  5242.         movea.l    MyScreen,a0
  5243.         move.b    (sc_WBorLeft,a0),d0
  5244.         add.b    (sc_WBorRight,a0),d0
  5245.         ext.w    d0
  5246.         sub.w    WinWidth,d0
  5247.         neg.w    d0
  5248.         move.w    d0,InnWidth
  5249.  
  5250. .skip        move.w    WinHeight,d0
  5251.         cmp.w    (sc_Height,a5),d0 ;d0<=sc_Height?
  5252.         bls.s    .skip2
  5253.         move.w    (sc_Height,a5),WinHeight
  5254.         st    Disable
  5255.         st    DisplayTooBig    ;inform the user
  5256.     ;  set new InnHeight
  5257.         movea.l    MyScreen,a0
  5258.         move.b    (sc_WBorBottom,a0),d0
  5259.         ext.w    d0
  5260.         add.w    winBarH,d0
  5261.         sub.w    WinHeight,d0
  5262.         neg.w    d0
  5263.         move.w    d0,InnHeight
  5264.  
  5265. .skip2
  5266.     ;**Set placement for the window
  5267.         movea.l    MyPrefs,a0
  5268.     ;  Get type of placement from prefs
  5269.         tst.b    (mprf_CenterWindow,a0)
  5270.         beq.s    InTheCenter    ;default
  5271.     ;  1. Abs position
  5272.         tst.b    CPointSet
  5273.         bne.s    InTheCenter
  5274.         st    CPointSet
  5275.         move.w    (mprf_WinX,a0),d0    ;set new center point
  5276.         move.w    d0,WinX
  5277.         move.w    WinWidth,d1
  5278.         asr.w    #1,d1
  5279.         add.w    d1,d0
  5280.         move.w    d0,CenterPointX
  5281.         move.w    (mprf_WinY,a0),d0
  5282.         move.w    d0,WinY
  5283.         move.w    WinHeight,d1
  5284.         asr.w    #1,d1
  5285.         add.w    d1,d0
  5286.         move.w    d0,CenterPointY
  5287.         bra.s    itc_skip
  5288.     ;  2. in the center of default screen
  5289. InTheCenter    move.w    WinWidth,d1
  5290.         asr.w    #1,d1        ;/2
  5291.         sub.w    CenterPointX,d1
  5292.         neg.w    d1
  5293.         move.w    d1,WinX
  5294.         move.w    WinHeight,d1
  5295.         asr.w    #1,d1
  5296.         sub.w    CenterPointY,d1
  5297.         neg.w    d1
  5298.         move.w    d1,WinY
  5299. itc_skip
  5300.         move.w    PFWidth,d0
  5301.         subq.w    #2,d0
  5302.         mulu.w    ButtWidth,d0
  5303.         move.w    d0,PFXPix
  5304.         move.w    PFHeight,d0
  5305.         subq.w    #2,d0
  5306.         mulu.w    ButtHeight,d0
  5307.         move.w    d0,PFYPix
  5308.         rts
  5309. ;-----------------------------------------------------------
  5310. SetZoomParams
  5311.     ;set zoom parameters
  5312.         move.w    DefPFSizes+(LEASY*8),d0    ;PFWidth for EASY level
  5313.         mulu.w    ButtWidth,d0
  5314.         move.b    ([MyScreen],sc_WBorLeft),d1
  5315.         add.b    ([MyScreen],sc_WBorRight),d1
  5316.         ext.w    d1
  5317.         add.w    d1,d0
  5318.         lea    ZoomParams,a0
  5319.         tst.w    (a0)        ;ZoomLeft already set by LoadPreferences?
  5320.         bpl.s    .yes1
  5321.         move.w    WinX,(a0)    ;left
  5322.         move.w    WinX,([MyPrefs],mprf_ZoomLeft)
  5323. .yes1        tst.w    (2,a0)        ;ZoomTop already set by LoadPreferences?
  5324.         bpl.s    .yes2
  5325.         move.w    WinY,(2,a0)    ;top
  5326.         move.w    WinY,([MyPrefs],mprf_ZoomTop)
  5327.  
  5328. .yes2        move.w    d0,(4,a0)    ;width
  5329.         move.w    winBarH,(6,a0)    ;height
  5330.         move.w    d0,ZoomWidth
  5331.         move.w    winBarH,ZoomHeight
  5332.         rts
  5333. ;-----------------------------------------------------------
  5334. SetWinTagList    ;Set values got from SetWinParams to MyWinTags
  5335.         lea    MyWinTags,a0
  5336. SetTagsLoop    move.l    (a0)+,d0
  5337.         beq.s    .done        ;TAG_DONE
  5338.         cmpi.l    #WA_InnerWidth,d0
  5339.         beq.s    .innwidth
  5340.         cmpi.l    #WA_InnerHeight,d0
  5341.         beq.s    .innheight
  5342.         cmpi.l    #WA_Left,d0    ;set WinX?
  5343.         beq.s    .left
  5344.         cmpi.l    #WA_Top,d0    ;set WinY?
  5345.         beq.s    .top
  5346.         cmpi.l    #WA_Activate,d0
  5347.         beq.s    .activate
  5348.         cmpi.l    #WA_CustomScreen,d0
  5349.         beq.s    .custom
  5350.         cmpi.l    #WA_PubScreenName,d0
  5351.         beq.s    .pubscreen
  5352.  
  5353. .nexttag    addq.w    #4,a0    ;skip ti_Data
  5354.         bra.s    SetTagsLoop
  5355.  
  5356. .done        rts        ;SetWinTags EXIT
  5357.  
  5358. .innwidth    move.w    InnWidth,(2,a0)
  5359.         bra.s    .nexttag
  5360. .innheight    move.w    InnHeight,(2,a0)
  5361.         bra.s    .nexttag
  5362. .left        move.w    WinX,(2,a0)
  5363.         bra.s    .nexttag
  5364. .top        move.w    WinY,(2,a0)
  5365.         bra.s    .nexttag
  5366.  
  5367. .activate    move.b    ([MyPrefs],mprf_WActivate),d0
  5368.         not.b    d0    ;inversed logic
  5369.         extb    d0
  5370.         move.l    d0,(a0)        ;WA_Activate flag
  5371.         bra.s    .nexttag
  5372.  
  5373. .custom        move.l    MyScreen,(a0)
  5374.         tst.b    ([MyPrefs],mprf_CustomScreen)
  5375.         bne.s    .nexttag
  5376.         move.l    #TAG_IGNORE,(-4,a0)
  5377.         bra.s    .nexttag
  5378.  
  5379. .pubscreen    move.l    ([MyPrefs],mprf_PubNameAdr),(a0)
  5380.         bra.s    .nexttag
  5381. ;*************************************************************************
  5382. ;*********LOAD FILE************
  5383.  
  5384. LOAD_FILE    ;IN: d0-filename
  5385.         ;OUT:d0-address of loaded data    ERROR=0
  5386.         ;    d1-lenght  of ^
  5387.  
  5388.         movem.l    d2-d7/a0-a6,-(sp)
  5389.         movea.l    DosBase,a6
  5390.         clr.l    lf_buffer
  5391.         clr.l    lf_fileLen
  5392.     ;***get lenght of the source file
  5393.         move.l    d0,lf_filename
  5394.  
  5395.         move.l    lf_filename,d1        ;filename
  5396.         move.l    #ACCESS_READ,d2    ;acces mode
  5397.         jsr    (_LVOLock,a6)    ;lock the file
  5398.         tst.l    d0
  5399.         beq.w    lf_nolock
  5400.         move.l    d0,lf_fileLock    ;store pointer
  5401.  
  5402.         move.l    lf_fileLock,d1
  5403.         move.l    #lf_fib,d2        ;file info block
  5404.         jsr    (_LVOExamine,a6)    ;fill the FIB structure
  5405.         tst.l    d0
  5406.         beq.s    lf_unlock
  5407.         move.l    lf_fib+$7c,lf_fileLen
  5408.  
  5409.     ;***Allocate memory buffer
  5410.         move.l    lf_fileLen,d0    ;file lenght=size of buffer
  5411.         moveq    #MEMF_PUBLIC,d1
  5412.         bsr    ADDALLOC
  5413.         move.l    d0,lf_buffer
  5414.         beq.s    lf_no_mem
  5415.  
  5416.     ;***open file to be loaded
  5417.         move.l    lf_filename,d1    ;source filename
  5418.         move.l    #MODE_OLDFILE,d2 ;acces mode
  5419.         jsr    (_LVOOpen,a6)    ;open file
  5420.         move.l    d0,lf_fhandle
  5421.         beq.s    lf_erroropen
  5422.  
  5423.     ;***load file to buffer
  5424.         move.l    lf_fhandle,d1    ;file
  5425.         move.l    lf_buffer,d2
  5426.         move.l    lf_fileLen,d3
  5427.         jsr    (_LVORead,a6)    ;read from file
  5428.         cmp.l    d0,d3
  5429.         bne.s    lf_Error
  5430.  
  5431. EndOfFile ;***file loaded->close and unlock
  5432. lf_close    move.l    lf_fhandle,d1
  5433.         jsr    (_LVOClose,a6)
  5434. lf_unlock    move.l    lf_fileLock,d1
  5435.         jsr    (_LVOUnLock,a6)
  5436.  
  5437. lf_nolock    move.l    lf_buffer,d0
  5438.         move.l    lf_fileLen,d1
  5439.         movem.l    (sp)+,d2-d7/a0-a6
  5440.         rts
  5441. ;------------------
  5442. lf_Error    clr.l    lf_buffer
  5443.         bra.s    lf_close
  5444. lf_no_mem
  5445. lf_erroropen    clr.l    lf_buffer
  5446.         bra.s    lf_unlock
  5447. ;**************SAVE FILE*******************************************************
  5448. SAVE_FILE    ;IN: d0-filename
  5449.         ;    d1-data
  5450.         ;    d2-lenght
  5451.         ;OUT: d0=0 => O.K.
  5452.  
  5453.         movem.l    d1-d7/a0-a6,-(sp)
  5454.         movea.l    DosBase,a6
  5455.         move.l    d0,lf_filename
  5456.         move.l    d1,d4        ;store
  5457.         move.l    d2,d5
  5458.  
  5459.     ;***Open file
  5460.         move.l    lf_filename,d1
  5461.         move.l    #MODE_NEWFILE,d2
  5462.         jsr    (_LVOOpen,a6)    ;open file
  5463.         move.l    d0,lf_fhandle
  5464.         beq.s    sf_erroropen
  5465.     ;***write buffer
  5466.         move.l    lf_fhandle,d1    ;fhandle
  5467.         move.l    d4,d2        ;buffer
  5468.         move.l    d5,d3        ;lenght
  5469.         jsr    (_LVOWrite,a6)
  5470.         cmp.l    d0,d3
  5471.         bne.s    sf_errorwrite
  5472.  
  5473.     ;***saved->close file
  5474.         clr.l    -(sp)
  5475. sf_close    move.l    lf_fhandle,d1
  5476.         jsr    (_LVOClose,a6)
  5477.  
  5478. sf_exit
  5479.         move.l    (sp)+,d0
  5480.         movem.l    (sp)+,d1-d7/a0-a6
  5481.         rts
  5482. sf_erroropen    move.l    #-1,-(sp)
  5483.         bra.s    sf_exit
  5484. sf_errorwrite    move.l    #-1,-(sp)
  5485.         bra.s    sf_close
  5486. ;*****************************************************************
  5487. ADDALLOC    ;IN - d0-size,d1-flags
  5488.         movem.l    a0/a1/a6,-(sp)
  5489.         movea.l    (EB,PC),a6
  5490.         move.l    d0,-(sp)    ;store size
  5491.         jsr    (_LVOAllocMem,a6)
  5492.         movea.l    AllocPos,a0
  5493.         move.l    d0,(a0)+    ;addr
  5494.         beq.s    .nomem
  5495.         addq.l    #8,AllocPos
  5496. .nomem        move.l    (sp)+,(a0)    ;size
  5497.         movem.l    (sp)+,a0/a1/a6
  5498.         rts
  5499. ;*****************************************************************
  5500. ;********FreeAllMemory    ;..also if nothing was allocated.
  5501. FreeAllMemory    move.l    (EB,PC),a6
  5502.         lea    Allocated,a5
  5503. FM_Loop        move.l    (a5)+,d0    ;Get addr
  5504.         beq.s    FM_Done        ;End of structure?
  5505.         movea.l    d0,a1
  5506.         move.l    (a5)+,d0    ;Get size
  5507.         jsr    (_LVOFreeMem,a6)    ;Free block
  5508.         bra.s    FM_Loop
  5509. FM_Done        rts
  5510. ;*****************************************************************
  5511. FreeMemBlock    ;IN: a1-address
  5512.         ;Searches in the "Allocated" structure
  5513.         ;for matching values and frees memory
  5514.         movem.l    d0/d1/a0/a6,-(sp)
  5515.         lea    Allocated,a0
  5516. fmb_next    move.l    (a0)+,d1
  5517.         beq.s    fmb_NotFound
  5518.         move.l    (a0)+,d0    ;size
  5519.         cmpa.l    d1,a1    ;check address
  5520.         bne.s    fmb_next
  5521.     ;found. Free it now.
  5522.         move.l    a0,-(sp)    ;store structure position
  5523.         movea.l    (EB,PC),a6
  5524.         jsr    (_LVOFreeMem,a6)
  5525.     ;cut item from the structure
  5526.         movea.l    (sp)+,a0
  5527.         movea.l    a0,a1
  5528.         subq.l    #8,a0    ;free block
  5529. .loop        move.l    (a1)+,(a0)+
  5530.         beq.s    .ok
  5531.         move.l    (a1)+,(a0)+
  5532.         bra.s    .loop
  5533. .ok        subq.l    #8,AllocPos    ;structure is now shorter
  5534. fmb_NotFound    movem.l    (sp)+,d0/d1/a0/a6
  5535.         rts
  5536.  
  5537. ;---------------------------------------------------------------------------
  5538. InitSemaphore    ;IN: NIL  OUT: d0 - addr. of the structure or FALSE
  5539.         ;Unfortunally, when calling this routine the ADDALLOC
  5540.         ;system is not initialized yet, so don't forget to free
  5541.         ;"Semaphore" manually (call "FreeSemaphore")
  5542.  
  5543.         movea.l    (EB,PC),a6
  5544.         move.l    #SS_SIZE,d0    ;Signal semaphore - sizeof
  5545.         move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  5546.         jsr    (_LVOAllocMem,a6)
  5547.         move.l    d0,Semaphore
  5548.         beq.s    .error
  5549.         move.l    d0,d2    ;store
  5550.         movea.l    (EB,PC),a6
  5551.         movea.l    d0,a0
  5552.         jsr    (_LVOInitSemaphore,a6)    ;void()
  5553.         move.l    d2,d0    ;ret. code
  5554. .error        rts
  5555.  
  5556. FreeSemaphore    movea.l    (EB,PC),a6
  5557.         movea.l    Semaphore,a1
  5558.         move.l    #SS_SIZE,d0
  5559.         jsr    (_LVOFreeMem,a6)
  5560.         rts
  5561. ;---------------------------------------------------------------------------
  5562. CallOtherSweeper
  5563.         bsr.s    InitSemaphore
  5564.         tst.l    d0
  5565.         beq.s    .noSemaphore
  5566.  
  5567.         movea.l    (EB,PC),a6
  5568.         jsr    (_LVOCreateMsgPort,a6)
  5569.         tst.l    d0
  5570.         beq.s    .exit
  5571.         movea.l    d0,a4    ;store
  5572.  
  5573.         movea.l    Semaphore,a0
  5574.         jsr    (_LVOObtainSemaphore,a6)
  5575.         lea    (MinesPortName,pc),a1
  5576.         jsr    (_LVOFindPort,a6)
  5577.         tst.l    d0
  5578.         beq.s    .nomines
  5579.         movea.l    d0,a3
  5580.  
  5581.         lea    (COSMsg,pc),a1        ;msg
  5582.         move.l    a4,(MN_REPLYPORT,a1)
  5583.         move.w    #am_ID+4,(MN_LENGTH,a1)
  5584.         move.l    #'MINE',(am_ID,a1)
  5585.         movea.l    a3,a0            ;port
  5586.         jsr    (_LVOPutMsg,a6)        ;hey! wake up!
  5587.  
  5588.         movea.l    a4,a0
  5589.         jsr    (_LVOWaitPort,a6)    ;wait for reply
  5590.  
  5591.         addq.l    #4,a7    ;rts
  5592.         movea.l    Semaphore,a0
  5593.         jsr    (_LVOReleaseSemaphore,a6)
  5594.         bsr.w    FreeSemaphore
  5595.         bra.s    .skp
  5596. .nomines
  5597.         movea.l    Semaphore,a0
  5598.         jsr    (_LVOReleaseSemaphore,a6)
  5599. .skp
  5600.         movea.l    a4,a0
  5601.         jsr    (_LVODeleteMsgPort,a6)
  5602.         rts
  5603.  
  5604. .exit
  5605.     ;free Semaphore structure
  5606.         bsr.w    FreeSemaphore
  5607.  
  5608. .noSemaphore    addq.l    #4,a7    ;rts
  5609.         rts
  5610.  
  5611. COSMsg        dcb.b    am_ID+4,0
  5612.         cnop    0,4
  5613. ;*****************************************************************
  5614. EB        dc.l    0    ;****ExecBase
  5615. ;*****************************************************************
  5616.         SECTION    wbstartup,CODE
  5617. _IconStart    movem.l    d0/a0,-(sp)    ;prik. radka
  5618.         sub.l    a1,a1        ;a1=0 - vlastni task
  5619.         movea.l    4.w,a6
  5620.         jsr    (_LVOFindTask,a6)
  5621.         movea.l    d0,a2
  5622.         tst.l    ($ac,a2)        ;z WB?  pr_CLI
  5623.         bne.s    From_CLI        ; ne
  5624. * from WorkBench *
  5625.         lea    ($5c,a2),a2    ;pr_MsgPort
  5626.         move.l    a2,a0
  5627.         jsr    (_LVOWaitPort,a6)
  5628.         move.l    a2,a0
  5629.         jsr    (_LVOGetMsg,a6)
  5630.         lea    (WBmessage,PC),a0
  5631.         move.l    d0,(a0)
  5632.         movem.l    (sp)+,d0/a0
  5633.         bra.s    CoWB_run
  5634. From_CLI    movem.l    (sp)+,d0/a0    ;d0 = d×lka pÒÉk. ÒÁdky vÃetnÅ LF ($a)
  5635.                     ;a0 ->na 1. znak ÒÁdky (Ucase<>Lcase)
  5636. CoWB_run    jsr    _main
  5637. CoWB_end    move.l    d0,-(sp)    ;returncode
  5638. * nÁvrat do CLI | WB ? *-------------------------
  5639.  
  5640.         tst.l    (WBmessage,pc)
  5641.         beq.s    To_CLI
  5642.         movea.l    4.w,a6
  5643.         jsr    (_LVOForbid,a6)
  5644.         move.l    (WBmessage,pc),a1
  5645.         jsr    (_LVOReplyMsg,a6)
  5646. To_CLI        move.l    (sp)+,d0            ;Errorcode
  5647.         rts
  5648.  
  5649. WBmessage    dc.l    0
  5650.  
  5651.         SECTION    GfxData,DATA_C
  5652.         INCDIR    "SOURCES:Mines/gfx/"
  5653. rawFlag        INCBIN    "Flag.raw"
  5654. rawNoFlag    INCBIN    "NoFlag.raw"
  5655. rawBomb        INCBIN    "Bomb.raw"
  5656. rawBlowed    INCBIN    "Blowed.raw"
  5657. rawMagicFlag    INCBIN    "MagicFlag.raw"
  5658. rawMagicNoFlag    INCBIN    "MagicNoFlag.raw"
  5659. rawMagicBomb    INCBIN    "MagicBomb.raw"
  5660. rawMagicBlowed    INCBIN    "MagicBlowed.raw"
  5661.  
  5662. rawSun        INCBIN    "Sun.raw"
  5663. rawSunPressed    INCBIN    "Sun.pressed.raw"
  5664. rawSunLoose    INCBIN    "Sun.loose.raw"
  5665. rawSunWon    INCBIN    "Sun.won.raw"
  5666. rawNumbers    INCBIN    "Numbers1bpl.raw"
  5667.  
  5668.         SECTION    MinesData,DATA
  5669.     ;**Bitmap structures for predefined gfx
  5670. bmapFlag    dc.w    ((BUTMINX-1)/16+1)*2    ;bm_BytesPerRow
  5671.         dc.w    BUTMINY            ;bm_Rows
  5672.         dc.b    0            ;bm_Flags
  5673.         dc.b    BUTMAXBPL        ;bm_Depth
  5674.         dc.w    0            ;bm_Pad
  5675.         dc.l    0,0,0,0,0,0,0,0
  5676.  
  5677. bmapNoFlag    dc.w    ((BUTMINX-1)/16+1)*2    ;bm_BytesPerRow
  5678.         dc.w    BUTMINY            ;bm_Rows
  5679.         dc.b    0            ;bm_Flags
  5680.         dc.b    BUTMAXBPL        ;bm_Depth
  5681.         dc.w    0            ;bm_Pad
  5682.         dc.l    0,0,0,0,0,0,0,0
  5683.  
  5684. bmapBomb    dc.w    ((BUTMINX-1)/16+1)*2    ;bm_BytesPerRow
  5685.         dc.w    BUTMINY            ;bm_Rows
  5686.         dc.b    0            ;bm_Flags
  5687.         dc.b    BUTMAXBPL        ;bm_Depth
  5688.         dc.w    0            ;bm_Pad
  5689.         dc.l    0,0,0,0,0,0,0,0
  5690.  
  5691. bmapBlowed    dc.w    ((BUTMINX-1)/16+1)*2    ;bm_BytesPerRow
  5692.         dc.w    BUTMINY            ;bm_Rows
  5693.         dc.b    0            ;bm_Flags
  5694.         dc.b    BUTMAXBPL        ;bm_Depth
  5695.         dc.w    0            ;bm_Pad
  5696.         dc.l    0,0,0,0,0,0,0,0
  5697.  
  5698.     ;**image structures for gadget-sun
  5699. img_Sun        dc.w    0        ;ig_LeftEdge 
  5700.         dc.w    0        ;ig_TopEdge
  5701.         dc.w    SUNMINX        ;ig_Width (though data is word-aligned)
  5702.         dc.w    SUNMINY        ;ig_Height
  5703.         dc.w    SUNMAXBPL    ;ig_Depth
  5704.         dc.l    rawSun        ;ig_ImageData
  5705.         dc.b    %111,0
  5706.         dc.l    0
  5707. img_SunPressed    dc.w    0        ;ig_LeftEdge 
  5708.         dc.w    0        ;ig_TopEdge
  5709.         dc.w    SUNMINX        ;ig_Width (though data is word-aligned)
  5710.         dc.w    SUNMINY        ;ig_Height
  5711.         dc.w    SUNMAXBPL    ;ig_Depth
  5712.         dc.l    rawSunPressed    ;ig_ImageData
  5713.         dc.b    %111,0
  5714.         dc.l    0
  5715. img_SunLoose    dc.w    0        ;ig_LeftEdge 
  5716.         dc.w    0        ;ig_TopEdge
  5717.         dc.w    SUNMINX        ;ig_Width (though data is word-aligned)
  5718.         dc.w    SUNMINY        ;ig_Height
  5719.         dc.w    SUNMAXBPL    ;ig_Depth
  5720.         dc.l    rawSunLoose    ;ig_ImageData
  5721.         dc.b    %111,0
  5722.         dc.l    0
  5723. img_SunWon    dc.w    0        ;ig_LeftEdge 
  5724.         dc.w    0        ;ig_TopEdge
  5725.         dc.w    SUNMINX        ;ig_Width (though data is word-aligned)
  5726.         dc.w    SUNMINY        ;ig_Height
  5727.         dc.w    SUNMAXBPL    ;ig_Depth
  5728.         dc.l    rawSunWon    ;ig_ImageData
  5729.         dc.b    %111,0
  5730.         dc.l    0
  5731.  
  5732. img_Number    dc.w    0        ;ig_LeftEdge 
  5733.         dc.w    0        ;ig_TopEdge
  5734.         dc.w    NUMWIDTH    ;ig_Width (though data is word-aligned)
  5735.         dc.w    NUMHEIGHT    ;ig_Height
  5736.         dc.w    2        ;ig_Depth
  5737.         dc.l    0        ;ig_ImageData
  5738.         dc.b    %100,0        ;ig_PlanePick,ig_PlaneOnOff
  5739.         dc.l    0
  5740.  
  5741.  
  5742. SunGadget    dc.l    0        ;gg_NextGadget
  5743.         dc.w    0        ;gg_LeftEdge
  5744.         dc.w    0        ;gg_TopEdge
  5745.         dc.w    SUNMINX        ;gg_Width
  5746.         dc.w    SUNMINY        ;gg_Height
  5747.         dc.w    GFLG_GADGIMAGE!GFLG_GADGHIMAGE    ;gg_Flags
  5748.         dc.w    GACT_RELVERIFY!GACT_IMMEDIATE    ;gg_Activation
  5749.         dc.w    0        ;gg_GadgetType
  5750.         dc.l    0        ;gg_GadgetRender
  5751.         dc.l    0        ;gg_SelectRender
  5752.         dc.l    0        ;gg_GadgetText        ; text for this gadget;
  5753.         dc.l    0        ;gg_MutualExclude     ; obsolete
  5754.         dc.l    0        ;gg_SpecialInfo
  5755.         dc.w    0        ;gg_GadgetID    ; user-definable ID field
  5756.         dc.l    0        ;gg_UserData    ;(ignored by Intuit)
  5757. Gadget_Image    dc.l    0
  5758. ;-----------------EndGadget
  5759. ;-------------------------------------------------------------------
  5760. IntuiName    dc.b    'intuition.library',0
  5761. GfxName        dc.b    'graphics.library',0
  5762. DosName        dc.b    'dos.library',0
  5763. ReqToolsName    dc.b    'reqtools.library',0
  5764. DiskFontName    dc.b    'diskfont.library',0
  5765. GadtoolsName    dc.b    'gadtools.library',0
  5766. UtilityName    dc.b    'utility.library',0
  5767.  
  5768. TimDevName    dc.b    'timer.device',0
  5769.  
  5770. wbName        dc.b    'Workbench',0
  5771.  
  5772.     ;**This is the main window**********************************
  5773.         cnop    0,4
  5774. MyWinTags
  5775.         dc.l    WA_Left,0
  5776.         dc.l    WA_Top,0
  5777.         dc.l    WA_InnerWidth,0
  5778.         dc.l    WA_InnerHeight,0
  5779.  
  5780.         dc.l    WA_CustomScreen,0
  5781.         dc.l    WA_Title,MyWinTitle
  5782.         dc.l    WA_ScreenTitle,MyWinScrTitle
  5783.         dc.l    WA_PubScreenName,0
  5784.  
  5785.     ;  **some flags now
  5786.         dc.l    WA_Activate,FALSE    ;default is false
  5787.         dc.l    WA_DragBar,TRUE
  5788.         dc.l    WA_DepthGadget,TRUE
  5789.         dc.l    WA_CloseGadget,TRUE
  5790.         dc.l    WA_Zoom,ZoomParams
  5791.         dc.l    WA_SmartRefresh,TRUE
  5792.         dc.l    WA_NewLookMenus,TRUE    ;V39
  5793.         dc.l    WA_ReportMouse,TRUE
  5794.         dc.l    WA_IDCMP,0
  5795.         dc.l    WA_Gadgets,0
  5796.         dc.l    WA_RptQueue,0
  5797.         dc.l    WA_MouseQueue,3
  5798.  
  5799.         dc.l    TAG_DONE,0
  5800.  
  5801. ZoomParams    dc.w    -1,-1,0,0
  5802.  
  5803.     ;***O.k. That was my window***********************************
  5804.     ;***Now the screen
  5805. MyScreenTags
  5806.         dc.l    SA_Title,MyScrTitle
  5807.         dc.l    SA_Type,CUSTOMSCREEN
  5808.         dc.l    SA_MinimizeISG,TRUE        ;V40
  5809.         dc.l    SA_AutoScroll,TRUE
  5810.         dc.l    SA_LikeWorkbench,0    ;V39
  5811.  
  5812.         dc.l    SA_Depth,BUTMAXBPL
  5813.         dc.l    SA_Left,0
  5814.         dc.l    SA_Top,0
  5815.         dc.l    SA_Width,0    ;set by OpenMyScreen
  5816.         dc.l    SA_Height,0
  5817.         dc.l    SA_Overscan,OSCAN_TEXT
  5818.         dc.l    SA_Pens,newLook
  5819.         dc.l    SA_SysFont,1    ;WB screen font
  5820.         dc.l    SA_DisplayID,0
  5821.         dc.l    TAG_DONE,0
  5822.  
  5823. newLook        dc.w    -1
  5824.  
  5825. PALENTRIES    =    8
  5826. DefaultPalette    dc.w    PALENTRIES,0
  5827.         dc.l    $AAAAAAAA,$AAAAAAAA,$AAAAAAAA,$00000000,$00000000,$00000000
  5828.         dc.l    $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$66666666,$88888888,$BBBBBBBB
  5829.         dc.l    $EEEEEEEE,$44444444,$44444444,$55555555,$DDDDDDDD,$55555555
  5830.         dc.l    $00000000,$44444444,$DDDDDDDD,$EEEEEEEE,$99999999,$00000000
  5831.         dc.l    0
  5832.  
  5833. MagicPalette    dc.w    PALENTRIES,0
  5834.         dc.l    $95959595,$95959595,$95959595,$00000000,$00000000,$00000000
  5835.         dc.l    $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$3B3B3B3B,$67676767,$A2A2A2A2
  5836.         dc.l    $7B7B7B7B,$7B7B7B7B,$7B7B7B7B,$AFAFAFAF,$AFAFAFAF,$AFAFAFAF
  5837.         dc.l    $AAAAAAAA,$90909090,$7C7C7C7C,$FFFFFFFF,$A9A9A9A9,$97979797
  5838.         dc.l    0
  5839.  
  5840. MyWinTitle    dc.b    'MineSweeper '
  5841.         dc.b    V,E,R,S,I
  5842.         dc.b    0
  5843. MyScrTitle
  5844. MyWinScrTitle    dc.b    'MineSweeper '
  5845.         dc.b    V,E,R,S,I,'          PEGAS Software (May-1997)'
  5846.         dc.b    0
  5847.     ;just version information
  5848.         dc.b    0,'$VER: MineSweeper '
  5849.         dc.b    V,E,R,S,I
  5850.         dc.b    ' (21.5.97)',0
  5851.  
  5852.     ;*****Menu structures*************************
  5853.  
  5854.         cnop    0,4
  5855. NewMenuTags    dc.l    GTMN_FullMenu,TRUE
  5856.         dc.l    TAG_DONE,0
  5857.  
  5858. LayoutTags    dc.l    GTMN_NewLookMenus,TRUE
  5859.         dc.l    TAG_DONE,0
  5860.  
  5861. MyMenu        dc.b    NM_TITLE,0    ;They must be in this order...
  5862.         dc.w    0,0    ;MENUENABLED
  5863.         dc.l    0,0,MGame,0
  5864.         ;**
  5865.         dc.b    NM_ITEM,0
  5866.         dc.w    $f800,STDFLAGS
  5867.         dc.l    csStrt,0,MStart,mh_Start
  5868.  
  5869.         dc.b    NM_ITEM,0
  5870.         dc.w    $f800!1<<MIS,STDFLAGS
  5871.         dc.l    csPaus,0,MPause,mh_Pause
  5872.  
  5873.         dc.b    NM_ITEM,0
  5874.         dc.w    $f800!2<<MIS,STDFLAGS
  5875.         dc.l    csAbou,0,MAbout,mh_About
  5876.  
  5877.         dc.b    NM_ITEM,0
  5878.         dc.w    $f800!3<<MIS,0
  5879.         dc.l    0,0,NM_BARLABEL,0
  5880.  
  5881.         dc.b    NM_ITEM,0
  5882.         dc.w    $f800!4<<MIS,STDFLAGS
  5883.         dc.l    csIcon,0,MIcon,mh_Iconify
  5884.  
  5885.         dc.b    NM_ITEM,0
  5886.         dc.w    $f800!5<<MIS,STDFLAGS
  5887.         dc.l    csQuit,0,MQuit,mh_Quit
  5888.     ;***************************
  5889.         dc.b    NM_TITLE,0
  5890.         dc.w    0,0    ;MENUENABLED
  5891.         dc.l    0,0,MScores,0
  5892.  
  5893.         dc.b    NM_ITEM,0
  5894.         dc.w    $f801,STDFLAGS
  5895.         dc.l    csHisc,0,MHiScores,mh_HiScores
  5896.  
  5897.         dc.b    NM_ITEM,0
  5898.         dc.w    $f801!1<<MIS,STDFLAGS
  5899.         dc.l    0,0,MClearHi,0
  5900.  
  5901.             dc.b    NM_SUB,0
  5902.             dc.w    $0001!(1<<MIS),STDFLAGS
  5903.             dc.l    0,0,MClrCustom,mh_ClearCustom
  5904.  
  5905.             dc.b    NM_SUB,0
  5906.             dc.w    $0001!(1<<MIS)!(1<<SIS),STDFLAGS
  5907.             dc.l    0,0,MClrAll,mh_ClearAll
  5908.  
  5909.         dc.b    NM_ITEM,0
  5910.         dc.w    $f801!2<<MIS,STDFLAGS
  5911.         dc.l    0,0,MJoin,mh_JoinScores
  5912.  
  5913.         dc.b    NM_ITEM,0
  5914.         dc.w    $f801!3<<MIS,STDFLAGS
  5915.         dc.l    csSaHi,0,MSave,mh_SaveScores
  5916.     ;***************************
  5917.         dc.b    NM_TITLE,0
  5918.         dc.w    0,0    ;MENUENABLED
  5919.         dc.l    0,0,MLevel,0
  5920.  
  5921. LevelItems    dc.b    NM_ITEM,0
  5922.         dc.w    $f802,MCHECK
  5923.         dc.l    csLev1,$fffe,MEasy,mh_Level
  5924.  
  5925.         dc.b    NM_ITEM,0
  5926.         dc.w    $f802!1<<MIS,MCHECK
  5927.         dc.l    csLev2,$fffd,MMedium,mh_Level
  5928.  
  5929.         dc.b    NM_ITEM,0
  5930.         dc.w    $f802!2<<MIS,MCHECK
  5931.         dc.l    csLev3,$fffb,MHard,mh_Level
  5932.  
  5933.         dc.b    NM_ITEM,0
  5934.         dc.w    $f802!3<<MIS,MCHECK
  5935.         dc.l    csLev4,$fff7,MProfi,mh_Level
  5936.  
  5937.         dc.b    NM_ITEM,0
  5938.         dc.w    $f802!4<<MIS,MCHECK
  5939.         dc.l    csLev5,$ffef,MCustom,mh_Level
  5940.     ;***************************
  5941.         dc.b    NM_TITLE,0
  5942.         dc.w    0,0    ;MENUENABLED
  5943.         dc.l    0,0,MSettings,0
  5944.         ;**
  5945.  
  5946.         dc.b    NM_ITEM,0
  5947.         dc.w    $f803,STDFLAGS
  5948.         dc.l    csPref,0,MPrefs,mh_AdjustPrefs
  5949.  
  5950.         dc.b    NM_ITEM,0
  5951.         dc.w    $f803!1<<MIS,STDFLAGS
  5952.         dc.l    0,0,MSavePrefs,mh_SavePrefs
  5953.  
  5954.         dc.b    NM_END,0
  5955.         dc.l    0,0,0,0,0
  5956.  
  5957. MMI_NUMOF    =    25    ;don't forget!! (include NM_END)
  5958.  
  5959. csStrt        dc.b    'S'
  5960. csAbou        dc.b    '?'
  5961. csHisc        dc.b    'H'
  5962. csSaHi        dc.b    'W'
  5963. csLev1        dc.b    '1'
  5964. csLev2        dc.b    '2'
  5965. csLev3        dc.b    '3'
  5966. csLev4        dc.b    '4'
  5967. csLev5        dc.b    '5'
  5968. csIcon        dc.b    'I'
  5969. csQuit        dc.b    'Q'
  5970. csPref        dc.b    'A'
  5971. csPaus        dc.b    'P'
  5972.  
  5973. MGame        dc.b    'GAME',0
  5974. MStart        dc.b    'Start',0
  5975. MPause        dc.b    'Pause',0
  5976. MAbout        dc.b    'About',0
  5977. MIcon        dc.b    'Iconify   ',0
  5978. MQuit        dc.b    'QUIT',0
  5979.  
  5980. MScores        dc.b    'Hi-Scores',0
  5981. MHiScores    dc.b    'Show',0
  5982. MClearHi    dc.b    'Clear    ',0
  5983. MClrCustom    dc.b     'Custom',0
  5984. MClrAll        dc.b     'All',0
  5985. MJoin        dc.b    'Join',0
  5986. MSave        dc.b    'Save',0
  5987.  
  5988. MLevel        dc.b    'Level',0
  5989.  
  5990. MEasy        dc.b    'Easy',0
  5991. MMedium        dc.b    'Medium',0
  5992. MHard        dc.b    'Hard',0
  5993. MProfi        dc.b    'Profi',0
  5994. MCustom        dc.b    'Custom',0
  5995.  
  5996. MSettings    dc.b    'Settings',0
  5997. MPrefs        dc.b    'Adjust',0
  5998. MSavePrefs    dc.b    'Save',0
  5999.  
  6000. ;**inform. requests
  6001. nointui_Text    dc.b    '"intuition.library" V39 required!',0
  6002. nointui_Button    dc.b    'I see.',0
  6003. nodos_Text    dc.b    '"dos.library" V36 required!',0
  6004. nodos_Button    dc.b    'I see.',0
  6005. nogfx_Text    dc.b    '"graphics.library" V39 required!',0
  6006. nogfx_Button    dc.b    'I see.',0
  6007. nogad_Text    dc.b    '"gadtools.library" V36 required!',0
  6008. nogad_Button    dc.b    'I see.',0
  6009. noutility_Text    dc.b    '"utility.library V36 required!',0
  6010. noutility_Button dc.b    'I see.',0
  6011.  
  6012. noreq_Text    dc.b    '"reqtools.library" V38 required!',10,0 ;for PrintText
  6013. notclosed_Text    dc.b    'ERROR: Couldn',39,'t close output file.',0
  6014.  
  6015. nomenu_Text    dc.b    'Couldn',39,'t allocate menu structures.',0
  6016. nomenu_Button    dc.b    'Continue',0
  6017. NoScr_Text    dc.b    'Failed to open required screen.',0
  6018. NoScr_Button    dc.b    'Continue',0
  6019. nowin_Text    dc.b    'Failed to open required window.',0
  6020. nowin_Button    dc.b    'Continue',0
  6021. nofont_Text    dc.b    'Failed to open required font.',10
  6022.         dc.b    'Default font is used.',0
  6023. nofont_Button    dc.b    'I see.',0
  6024. noprefs_Text    dc.b    'There',39,'s no memory for Preference structure.',0
  6025. noprefs_Button    dc.b    'Exit',0
  6026. changed_Text    dc.b    'Hey! Somebody has changed the window!!',10
  6027.         dc.b    '( Sorry, not me!! )',0
  6028. changed_Button    dc.b    'Well...',0
  6029. nomygfx_Text    dc.b    'No chip memory for gfx.',0
  6030. nomygfx_Button    dc.b    'Well...',0
  6031. nopf_Text    dc.b    'Fatal lack of memory.',0
  6032. nopf_Button    dc.b    'Exit MineSweeper',0
  6033. pfbig_Text    dc.b    'Sorry, but the required playfield is too big.',10
  6034.         dc.b    'I can handle only 65535 buttons.',10
  6035.         dc.b    '( That',39,'s e.G. 85 x 771 or 255 x 257 :)',10,10
  6036.         dc.b    'Sorry, but this is a fatal error :( ',0
  6037. pfbig_Button    dc.b    'Exit MineSweeper',0
  6038. toobig_Text    dc.b    'The playfield size is too big for your screen.',0
  6039. toobig_Button    dc.b    'I see..',0
  6040. oldproc_Text    dc.b    'Sorry, but I prefer a 68020+',0
  6041. oldproc_Button    dc.b    'O.K. I',39,'ll upgrade.',0
  6042. oldks_Text    dc.b    'System 3.0+ (V39+) required.',0
  6043. oldks_Button    dc.b    'No money.',0
  6044. notimd_Text    dc.b    'Sorry. Couldn',39,'t open "timer.device"',0
  6045. notimd_Button    dc.b    'Abort',0
  6046. unexp_Text    dc.b    'Couldn',39,'t open required window',10
  6047.         dc.b    '(perhaps low memory or something..)',0
  6048. unexp_Button    dc.b    'O.K.',0
  6049. nopubport_Text    dc.b    'Couldn',39,'t open message port.',0
  6050. nopubport_Button dc.b    'Leave',0
  6051. noidcmp_Text    dc.b    'Couldn',39,'t open IDCMP communication port.',0
  6052. noidcmp_Button    dc.b    'Exit',0
  6053. toolong_Text    dc.b    '(TIME OUT!)',10
  6054.         dc.b    'SORRY! UNFORTUNALLY, I WAS NOT INFORMED ABOUT YOUR IQ.',10
  6055.         dc.b    'BUT DO NOT PANIC. JUST MOVE THE POINTER TO THE BUTTON BELOW',10
  6056.         dc.b    'THIS TEXT AND PRESS LEFT BUTTON OF THE THING, YOU ARE MOVING WITH.',10
  6057.         dc.b    'THEN TRY TO FIND THE "CLOSE GADGET".',10
  6058.         dc.b    'IT IS IN THE UPPER-LEFT CORNER OF THE RECTANGLE,',10
  6059.         dc.b    'WHICH CONTAINS THOSE MANY SQUARES AND THE SUN. GOOD LUCK!',10
  6060.         dc.b    '(hope you got it..! :-)',0
  6061. toolong_Button    dc.b    'HERE!  PRESS HERE!!',0
  6062. toomuch_Text    dc.b    'There are too many mines on custom level.',10
  6063.         dc.b    'It must be max. Width*Height-1',0
  6064. toomuch_Button    dc.b    'O.K. Let',39,'s correct it.',0
  6065. toosmall_Text    dc.b    'The window would be too small for this button-sizes',10
  6066.         dc.b    'and the specified PF width.',0
  6067. toosmall_Button    dc.b    'OK Let',39,'s correct it',0
  6068. surec_Text    dc.b    'Are you sure to clear custom hi-scores?',0
  6069. surec_Button    dc.b    'Yes|No',0
  6070. surea_Text    dc.b    'Are you sure to clear all hi-scores?',0
  6071. surea_Button    dc.b    'Yes|No',0
  6072.  
  6073. xmas_Text    dc.b    '  --- PEGAS SOFTWARE WISH YOU MERRY CHRISTMAS ---',10,10
  6074.         dc.b    'These are personal wishes from Andry :',10
  6075.         dc.b    'Lack of depression, lot of love, many presents',10
  6076.         dc.b    'and a wonderful Christmas-tree.',10
  6077.         dc.b    '----------------------------------------------------',10,10
  6078.         dc.b    'Well, did you pay for this game?',10
  6079.         dc.b    'Not yet? ... oh , you are going to!',10
  6080.         dc.b    'Then it',39,'s all right.',0
  6081.  
  6082. xmas_Button    dc.b    'Enjoy MineSweeper',0
  6083.  
  6084. about_Text    dc.b    10,'MineSweeper '
  6085.         dc.b    V,E,R,S,I
  6086.         dc.b    10,'-----------------',10
  6087.         dc.b    'PEGAS Software  (Mai-1997)',10,10
  6088.         dc.b    '  Code: Andry  e-mail: xbednar@fi.muni.cz',10
  6089.         dc.b    '                  tel: +420-641-68284',10,10
  6090.         dc.b    '  Gfx : Troda  e-mail: kozubv@vtx.cz',10
  6091.         dc.b    '                  tel: +420-641-204595',10,10,10
  6092.         dc.b    '     Language: 100%% assembler',10
  6093.         dc.b    'Compiled with: PhxAss v4.35(alpha)  (freeware!!!)',10
  6094.         dc.b    '               by Frank Wille.  (Danke sehr :)',10,10
  6095.         dc.b    'This program is freeware, but a little support',10
  6096.         dc.b    'would be nice :)  ...refer to documentation.',10
  6097.         dc.b    0
  6098. about_Button    dc.b    'Enjoy!',0
  6099.  
  6100. HiScoresButton    dc.b    'Hmmm...',0
  6101. HiScoresButtonSave dc.b    'Save|Don',39,'t save',0
  6102.  
  6103. HsFileName    dc.b    'Mines.hiscores',0
  6104.         cnop    0,4
  6105.  
  6106. AboutTags
  6107. HiScoresTags    dc.l    RT_Window,0
  6108.         dc.l    RT_TextAttr,MyTextAttr
  6109.         dc.l    TAG_DONE,0
  6110. IReqTags    dc.l    RTEZ_Flags,EZREQF_CENTERTEXT
  6111.         dc.l    RT_Window,0
  6112.         dc.l    TAG_DONE,0
  6113. JoinGetTags    dc.l    RT_Window,0
  6114.         dc.l    RTFI_Flags,FREQF_MULTISELECT!FREQF_PATGAD
  6115.         dc.l    RTFI_OkText,join_Text
  6116.         dc.l    TAG_DONE,0
  6117. GSReqTags    dc.l    RT_Window,0
  6118.         dc.l    RTGS_Flags,GSREQF_CENTERTEXT
  6119.         dc.l    RTGS_TextFmt,hsgs_text
  6120.         dc.l    TAG_DONE,0
  6121.  
  6122. hsgs_text    dc.b    'You have reached the high score.',10
  6123.         dc.b    'Please enter your name.',0
  6124.         cnop    0,4
  6125. ;**For bevel boxes
  6126. VisualInfo    dc.l    0
  6127. dbb_TagList1    dc.l    GT_VisualInfo,0        ;normal button
  6128.         dc.l    GTBB_FrameType,BBFT_BUTTON
  6129.         dc.l    TAG_DONE,0
  6130. dbb_TagList2    dc.l    GT_VisualInfo,0        ;recessed button
  6131.         dc.l    GTBB_FrameType,BBFT_BUTTON
  6132.         dc.l    GTBB_Recessed,TRUE
  6133.         dc.l    TAG_DONE,0
  6134.  
  6135. MyTextAttr    dcb.b    ta_SIZEOF,0
  6136.  
  6137.         cnop    0,4
  6138. pnrt_Text    dc.l    0    ;ptr to the final text
  6139.  
  6140. pnrt_Button    dc.b    'I',39,'ll have a look',0
  6141.         cnop    0,4
  6142.  
  6143. PrefItems
  6144.         dc.l    PNameCustom,Pref_CustomScreen,sp_CustomScreen
  6145.         dc.l    PNamePub,Pref_PubScreen,sp_PubScreen
  6146.  
  6147.         dc.l    PNameLevel,Pref_Level,sp_Level
  6148.         dc.l    PNameCusWid,Pref_CusWid,sp_CusWid
  6149.         dc.l    PNameCusHei,Pref_CusHei,sp_CusHei
  6150.         dc.l    PNameCusBom,Pref_CusBom,sp_CusBom
  6151.  
  6152.         dc.l    PNameWBLike,Pref_WBLike,sp_WBLike
  6153.         dc.l    PNameNotCenter,Pref_NotCenter,sp_NotCenter
  6154.         dc.l    PNameNotActivate,Pref_NotActiv,sp_NotActiv
  6155.         dc.l    PNameNoQuestion,Pref_NoQuest,sp_NoQuest
  6156.         dc.l    PNameDeadQ,Pref_DeadQ,sp_DeadQ
  6157.         dc.l    PNameCountD,Pref_CountD,sp_CountD
  6158.         dc.l    PNameNoRMouse,Pref_NoRMouse,sp_NoRMouse
  6159.         dc.l    PNameWarn,Pref_Warn,sp_Warn
  6160.         dc.l    PNameScale,Pref_Scale,sp_Scale
  6161.  
  6162.         dc.l    PNamePalette,Pref_Palette,sp_Palette
  6163.         dc.l    PNameGfx,Pref_GfxType,sp_GfxType
  6164.         dc.l    PNameIconify,Pref_Iconify,sp_Iconify
  6165.         dc.l    PNameModeID,Pref_ModeID,sp_ModeID
  6166.         dc.l    PNameSizeX,Pref_SizeX,sp_SizeX
  6167.         dc.l    PNameSizeY,Pref_SizeY,sp_SizeY
  6168.         dc.l    PNameWinX,Pref_WinX,sp_WinX
  6169.         dc.l    PNameWinY,Pref_WinY,sp_WinY
  6170.         dc.l    PNameZoomX,Pref_ZoomX,sp_ZoomX
  6171.         dc.l    PNameZoomY,Pref_ZoomY,sp_ZoomY
  6172.  
  6173.         dc.l    PNameFont,Pref_Font,sp_Font
  6174.         dc.l    PNameFontSize,Pref_FontSize,sp_FontSize
  6175.         dc.l    0,0,0        ;end
  6176.  
  6177. PNamePub    dc.b    'PUBSCREEN',0
  6178. PNameCustom    dc.b    'CUSTOMSCREEN',0
  6179. PNameModeID    dc.b    'ModeID',0
  6180. PNameSizeX    dc.b    'Scr_Width',0
  6181. PNameSizeY    dc.b    'Scr_Height',0
  6182.  
  6183. PNameNotCenter    dc.b    'DONOTCENTER',0
  6184. PNameNotActivate dc.b    'DONOTACTIVATE',0
  6185. PNameWinX    dc.b    'Window_Left',0
  6186. PNameWinY    dc.b    'Window_Top',0
  6187. PNameZoomX    dc.b    'Paused_Left',0
  6188. PNameZoomY    dc.b    'Paused_Top',0
  6189.  
  6190. PNameLevel    dc.b    'Level',0
  6191. PNameCusWid    dc.b    'CUSTOM_WIDTH',0
  6192. PNameCusHei    dc.b    'CUSTOM_HEIGHT',0
  6193. PNameCusBom    dc.b    'CUSTOM_MINES',0
  6194.  
  6195. PNameFont    dc.b    'Font',0
  6196. PNameFontSize    dc.b    'FontSize',0
  6197. PNamePalette    dc.b    'PALETTE',0
  6198. PNameGfx    dc.b    'GFXTYPE',0
  6199.  
  6200. PNameNoQuestion    dc.b    'NOQMARK',0
  6201. PNameDeadQ    dc.b    'QUESTION_DEAD',0
  6202. PNameCountD    dc.b    'COUNTDOWN',0
  6203. PNameNoRMouse    dc.b    'NORMOUSEGAME',0
  6204. PNameWBLike    dc.b    'WBLIKE',0
  6205. PNameWarn    dc.b    'DONOTWARN',0
  6206. PNameIconify    dc.b    'ICONIFY',0
  6207. PNameScale    dc.b    'SCALEGFX',0
  6208. TOOLTYPEITEMS    =    27
  6209.  
  6210. ;***Structure Default playfield sizes
  6211.         even
  6212. DefPFSizes    dc.l    0,0    ;no data
  6213.         dc.w    EASYWIDTH
  6214.         dc.w    EASYHEIGHT
  6215.         dc.w    EASYBOMBS,0    ;zero just for allign (8)
  6216.         dc.w    MEDIUMWIDTH
  6217.         dc.w    MEDIUMHEIGHT
  6218.         dc.w    MEDIUMBOMBS,0
  6219.         dc.w    HARDWIDTH
  6220.         dc.w    HARDHEIGHT
  6221.         dc.w    HARDBOMBS,0
  6222.         dc.w    PROFIWIDTH
  6223.         dc.w    PROFIHEIGHT
  6224.         dc.w    PROFIBOMBS,0
  6225. cpf_Width    = 0
  6226. cpf_Height    = 2
  6227. cpf_Bombs    = 4
  6228. CusPFSizes    dc.w    MEDIUMWIDTH    ;for custom
  6229.         dc.w    MEDIUMHEIGHT
  6230.         dc.w    MEDIUMBOMBS,0
  6231.  
  6232. ;***Join Hi-Scores data
  6233. join_Text    dc.b    'Join',0
  6234. JoinFilename    dcb.b    108,0
  6235. JoinGetTitle    dc.b    'Select Hi-Score files',0
  6236.         cnop    0,4
  6237. JoinOldDir    dc.l    0
  6238. JoinDirLock    dc.l    0
  6239. JoinPrefsBuf    dc.l    0
  6240. JoinRequester    dc.l    0
  6241. JoinFileList    dc.l    0
  6242.  
  6243.         SECTION    BssVars,BSS
  6244.         cnop    0,4
  6245. Semaphore    ds.l    1    ;must not be cleared!
  6246.  
  6247. BssStart
  6248. IntuiBase    ds.l    1
  6249. _GfxBase    ds.l    1
  6250. DosBase        ds.l    1
  6251. _ReqToolsBase    ds.l    1
  6252. GadtoolsBase    ds.l    1
  6253. UtilityBase    ds.l    1
  6254.  
  6255. MyScreen    ds.l    1    ;pointer to the screen used (Workbench or custom)
  6256. MyWindow    ds.l    1
  6257. OldIDCMP    ds.l    1    ;IDCMP flags of my window
  6258. WinFont        ds.l    1    ;screen rastport font
  6259.  
  6260. MyFontName    ds.b    30
  6261.         cnop    0,4
  6262. SysTime        ds.l    2
  6263. OldSysTime    ds.l    2
  6264. MyTime        ds.l    2
  6265. Ctime        ds.l    2    ;current time
  6266. EndTime        ds.l    2
  6267. TimDevBase    ds.l    1
  6268. StartTime    ds.w    2
  6269.  
  6270. MenuStruct    ds.l    1
  6271.  
  6272. TimPort        ds.l    1
  6273. TimIoReq    ds.l    1
  6274. RndSeed        ds.l    1
  6275. Storage        ds.l    2    ;just 8 free bytes
  6276. OldDirectory    ds.l    1
  6277. ProgDir        ds.l    1
  6278. SeedFillStack    ds.l    1    ;adr
  6279. SeedFillSP    ds.l    1    ;ptr at end
  6280. MyPrefs        ds.l    1    ;ptr to MyPrefs structure
  6281. MyDrawInfo    ds.l    1
  6282. MGGfx        ds.l    1    ;ptr to an array of bitmap pointers
  6283. PFAdr        ds.l    1    ;ptr to play field
  6284. PFSize        ds.w    1    ;size of play field in bytes
  6285. WinCount    ds.w    1    ;howmany buttons to press before you win
  6286. MaxRandRange    ds.w    1
  6287. LastXmas    ds.w    1
  6288.  
  6289. MinRowBut    ds.w    1    ;minimum of buttons per row (pf width)
  6290. MyBarHeight    ds.w    1    ;size of main bar (note MYBARWIDTH is a constant)
  6291. winBarH        ds.w    1    ;height of the window bar
  6292. WinWidth    ds.w    1    ;MyWindow size
  6293. WinHeight    ds.w    1
  6294. ZoomWidth    ds.w    1
  6295. ZoomHeight    ds.w    1
  6296. WinX        ds.w    1    ;MyWindow position
  6297. WinY        ds.w    1
  6298. MinX        ds.w    1    ;upper left corner of the inner area
  6299. MinY        ds.w    1
  6300. MinPFX        ds.w    1    ;start of the playfield gfx
  6301. MinPFY        ds.w    1
  6302. PFXPix        ds.w    1    ;playfield size in pixels
  6303. PFYPix        ds.w    1
  6304. InnWidth    ds.w    1    ;size of the inner area
  6305. InnHeight    ds.w    1
  6306. PFWidth        ds.w    1    ;Play Field Size (buttons per x/y)
  6307. PFHeight    ds.w    1
  6308. PFBombs        ds.w    1
  6309. ButtWidth    ds.w    1    ;button size
  6310. ButtHeight    ds.w    1
  6311. TimeX        ds.w    1    ;position of Time and BCount displays
  6312. TimeY        ds.w    1
  6313. BCountX        ds.w    1
  6314. BCountY        ds.w    1
  6315. BCount        ds.w    1
  6316. CenterPointX    ds.w    1
  6317. CenterPointY    ds.w    1
  6318. LastX        ds.w    1
  6319. LastY        ds.w    1
  6320.  
  6321. ScreenPalette    ds.l    PALENTRIES*3+2
  6322.  
  6323. gtl_IText    ds.b    it_SIZEOF
  6324.  
  6325. ;***Some flags------------------
  6326. Play        ds.b    1    ;if set: timer, rmbtrap, ...
  6327. Win        ds.b    1    ;if won then 1
  6328. Ready        ds.b    1    ;if ready to play
  6329. HandleNext    ds.b    1    ;handle next selected menu?
  6330. IDidTheChange    ds.b    1    ;Who changed the window size?
  6331. Disable        ds.b    1    ;if set, disables drawing to screen and playing.
  6332.                 ;You can use menu (to change window size)
  6333. DisplayTooBig    ds.b    1    ;inform user, that he cannot play (disabled)
  6334. Sign        ds.b    1    ;sign flag for number converting
  6335. TimerGo        ds.b    1    ;timer stopped/running
  6336. FirstTime    ds.b    1
  6337. ValidHSText    ds.b    1
  6338. CPointSet    ds.b    1
  6339. TestXmas    ds.b    1
  6340. Pause        ds.b    1    ;game paused?
  6341. SunPressedOnce    ds.b    1
  6342. FromIconify    ds.b    1
  6343. PausedLevel    ds.b    1
  6344. ;------------------------------
  6345. LastLevel    ds.b    1
  6346.         cnop    0,4
  6347. Allocated    ds.l    MAXALLOCBLOCKS*2+2
  6348. AllocPos    ds.l    1
  6349.  
  6350. ;**********Load/Save file data
  6351. lf_filename    ds.l    1
  6352. lf_fhandle    ds.l    1
  6353. lf_fileLock    ds.l    1
  6354. lf_buffer    ds.l    1
  6355. lf_fileLen    ds.l    1
  6356. lf_fib        ds.b    $104    ;File_Info_Block
  6357.  
  6358. CurrDate    ds.b    CD_SIZE
  6359. GTNewMenu    ds.b    MMI_NUMOF*gnm_SIZEOF    ;buffer for NewMenu structures
  6360. IntuiMessBuf    ds.b    im_SIZEOF
  6361. NameBuffer    ds.b    NAMELEN
  6362. HiScoresText    ds.b    HS_TEXTMEM
  6363. PROGNAMELEN = 32
  6364. ProgramName    ds.b    PROGNAMELEN
  6365. WinPortSigBit    ds.b    1
  6366. PubPortSigBit    ds.b    1
  6367.         cnop    0,4
  6368. SignalBits    ds.l    1
  6369. bitScaleArgs    ds.w    bsa_SIZEOF/2
  6370.  
  6371.         cnop    0,4
  6372. BssSectionAlign    ds.l    1
  6373. BssEnd
  6374.